I'm trying to download file from Heroku's SFTP To Go using net/sftp gem but I always get undefined method `e=' for #.
Been searching online but can't find any related solutions. Here is my code:
task employer_email_import: :environment do
require 'net/sftp'
require 'uri'
sftptogo_url = ENV['SFTPTOGO_URL']
uri = URI.parse(sftptogo_url)
Net::SFTP.start(uri.host, uri.user, :password => uri.password) do |sftp|
sftp.download!("some_directory", "some_directory")
end
end
Error:
undefined method `e=' for #< OpenSSL::PKey::RSA:0x00563aaff72138>
Did you mean? e**********
"/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/buffer.rb:255:in read_keyblob'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/buffer.rb:239:inread_key'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:145:in block (2 levels) in keys_for'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:127:ineach_line'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:127:in block in keys_for'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:125:inopen'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:125:in keys_for'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:55:inblock in search_in'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:55:in map'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:55:insearch_in'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/known_hosts.rb:49:in search_for'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:96:inhost_keys'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/algorithms.rb:251:in prepare_preferred_algorithms!'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/algorithms.rb:124:ininitialize'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:86:in new'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:86:ininitialize'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in new'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:instart'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/net-sftp-2.1.2/lib/net/sftp.rb:31:in start'", "/home/romz/Desktop/Romz/site/ROR/recoverysuite/lib/tasks/scheduler.rake:376:inblock (2 levels) in '", "/home/romz/Desktop/Romz/site/ROR/recoverysuite/lib/tasks/scheduler.rake:353:in each'", "/home/romz/Desktop/Romz/site/ROR/recoverysuite/lib/tasks/scheduler.rake:353:inblock in '", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:248:in block in execute'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:243:ineach'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:243:in execute'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:187:inblock in invoke_with_call_chain'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/2.4.0/monitor.rb:214:in mon_synchronize'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:180:ininvoke_with_call_chain'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/task.rb:173:in invoke'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:152:ininvoke_task'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:108:in block (2 levels) in top_level'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:108:ineach'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:108:in block in top_level'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:117:inrun_with_threads'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:102:in top_level'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:80:inblock in run'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:178:in standard_exception_handling'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/lib/rake/application.rb:77:inrun'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-11.3.0/exe/rake:27:in <top (required)>'", "/home/romz/.rbenv/versions/2.4.0/bin/rake:23:inload'", "/home/romz/.rbenv/versions/2.4.0/bin/rake:23:in <top (required)>'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli/exec.rb:74:inload'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli/exec.rb:74:in kernel_load'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli/exec.rb:28:inrun'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli.rb:463:in exec'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:inrun'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in invoke_command'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/vendor/thor/lib/thor.rb:387:indispatch'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli.rb:27:in dispatch'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:instart'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/cli.rb:18:in start'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/exe/bundle:30:inblock in '", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/lib/bundler/friendly_errors.rb:124:in with_friendly_errors'", "/home/romz/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-2.0.1/exe/bundle:22:in'", "/home/romz/.rbenv/versions/2.4.0/bin/bundle:23:in load'", "/home/romz/.rbenv/versions/2.4.0/bin/bundle:23:in'"
RUBY_VERSION
=> "2.4.0"
OpenSSL::OPENSSL_VERSION
=> "OpenSSL 1.1.0g 2 Nov 2017"
OpenSSL::VERSION
=> "2.0.2"
rails --version
=> Rails 5.0.7.1
use:
gem 'net-sftp'
gem 'net-ssh', '~> 5.1.0'
gem 'openssl', '~> 2.0.0.beta.1'
this will solve your issue.
Related
When I try to run this one specific test, it gives this error. When I try to run all tests, it fails for another reason. How can I run this one test without this error? It's clearly a valid URL.
C:\Users\Chloe\workspace\catalyst_research>rspec ./spec/features/ctdbase_purchase_spec.rb:28
http://ctdbase.org/ # output of puts
1) CTD Purchase Unregistered user visits the CTD product page directly and makes purchase
Failure/Error: visit url
Addressable::URI::InvalidURIError:
Invalid scheme format: 127.0.0.1
# ./spec/support/ctdbase_support.rb:8:in `visit_ctd'
# ./spec/features/ctdbase_purchase_spec.rb:11:in `block (2 levels) in <top (required)>'
Here is the code
ctdbase_support.rb
def visit_ctd(path)
url = "#{CTD_URL}#{path.starts_with?('/') ? '' : '/'}#{path}"
puts url
visit url # line 8
end
ctdbase_purchase_spec.rb
before do
delete_downloads
visit_ctd '/' # line 11
Here is the full backtrace:
C:\Users\Chloe\workspace\catalyst_research>rspec -b ./spec/features/ctdbase_purchase_spec.rb:28
...
1) CTD Purchase Unregistered user visits the CTD product page directly and makes purchase
Failure/Error: visit "#{CTD_URL}#{path.starts_with?('/') ? '' : '/'}#{path}"
Addressable::URI::InvalidURIError:
Invalid scheme format: 127.0.0.1
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:874:in `scheme='
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:799:in `block in initialize'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:2355:in `defer_validation'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:796:in `initialize'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:136:in `new'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/uri.rb:136:in `parse'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/addressable-2.5.2/lib/addressable/template.rb:413:in `match'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/request_pattern.rb:151:in `block in matches?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/request_pattern.rb:151:in `any?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/request_pattern.rb:151:in `matches?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/request_pattern.rb:33:in `matches?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/stub_registry.rb:58:in `block in request_stub_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/stub_registry.rb:57:in `each'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/stub_registry.rb:57:in `detect'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/stub_registry.rb:57:in `request_stub_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/stub_registry.rb:50:in `response_for_request'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/http_lib_adapters/net_http.rb:79:in `request'
# C:/ruby24/lib/ruby/2.4.0/net/http.rb:1165:in `get'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/server.rb:82:in `block in responsive?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/http_lib_adapters/net_http.rb:123:in `start_without_connect'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/webmock-3.0.1/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
# C:/ruby24/lib/ruby/2.4.0/net/http.rb:608:in `start'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/server.rb:82:in `responsive?'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/server.rb:98:in `boot'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/session.rb:88:in `initialize'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara.rb:304:in `new'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara.rb:304:in `current_session'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/dsl.rb:45:in `page'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/capybara-2.16.1/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-rails-3.7.2/lib/rspec/rails/example/feature_example_group.rb:29:in `visit'
# ./spec/support/ctdbase_support.rb:6:in `visit_ctd'
# ./spec/features/ctdbase_purchase_spec.rb:11:in `block (2 levels) in <top (required)>'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:447:in `instance_exec'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:447:in `instance_exec'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:350:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:509:in `block in run_owned_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:508:in `each'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:508:in `run_owned_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:595:in `block in run_example_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:594:in `reverse_each'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:594:in `run_example_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:464:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:494:in `run_before_example'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:253:in `block in run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:466:in `block in run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:606:in `block in run_around_example_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:342:in `call'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-rails-3.7.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:447:in `instance_exec'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:447:in `instance_exec'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:375:in `execute_with'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:608:in `block (2 levels) in run_around_example_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:342:in `call'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:609:in `run_around_example_hooks_for'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/hooks.rb:466:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example.rb:251:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example_group.rb:628:in `block in run_examples'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example_group.rb:624:in `map'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example_group.rb:624:in `run_examples'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/example_group.rb:590:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:118:in `map'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/configuration.rb:1896:in `with_suite_hooks'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:113:in `block in run_specs'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/reporter.rb:79:in `report'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:112:in `run_specs'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:87:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:71:in `run'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/lib/rspec/core/runner.rb:45:in `invoke'
# C:/ruby24/lib/ruby/gems/2.4.0/gems/rspec-core-3.7.0/exe/rspec:4:in `<top (required)>'
# C:/ruby24/bin/rspec:23:in `load'
# C:/ruby24/bin/rspec:23:in `<main>'
Seems this project is using WebMock. This is the webmock.rb file
spec/config/webmock.rb
require 'webmock/rspec'
WebMock.allow_net_connect!
GOOGLE_STUB_WITHOUT_IP = {
"city" => "Mountain View",
"region" => "California",
"region_code" => "CA",
"country" => "US",
"country_name" => "United States",
"continent_code" => "NA",
"postal" => "94035",
"latitude" => 37.386,
"longitude" => -122.0838,
"timezone" => "America/Los_Angeles",
"utc_offset" => "-0700",
"country_calling_code" => "+1",
"currency" => "USD",
"languages" => "en-US,es-US,haw,fr",
"asn" => "AS15169",
"org" => "Google LLC"
}
uri_template =
Addressable::Template.new "https://ipapi.co/{ip_address}/json/"
WebMock.stub_request(:get, uri_template).to_return { |request|
{
# FIXME: This should dynamically return the ip address
# body: GOOGLE_STUB_WITHOUT_IP.merge('ip' => request.ip_address)
body: GOOGLE_STUB_WITHOUT_IP.merge('ip' => '8.8.8.8').to_json,
headers: { 'Content-Type' => 'application/json' }
}
}
You're running into a bug in the combination of WebMock and Addressable - https://github.com/bblimke/webmock/issues/489 and https://github.com/bblimke/webmock/pull/739. The problem is that WebMock ends up creating variations of URLs to compare to templates, and ends up doing something like 127.0.0.1:<some_port>/__identify when Capybara starts the app. The proper solution is for WebMock to fix the URLs it's sending to Addressable, but you may be able to workaround it temporarily by setting Capybara.server_host='localhost' which will cause the URL variation to end up as localhost:<some_port>/__identify and Addressable will see localhost as a possible scheme (which could be valid). It's a hack, but it may hold you over until WebMock gets fixed. Another option would be to stop using URL templates with WebMock and use regex instead.
I want to use Mailjet in order to send order confirmation email.
First of all, I installed Gem and configure as Mailjet guide
gem 'mailjet'
initializers/mailjet.rb
Mailjet.configure do |config|
config.api_key = '<my_api_key>'
config.secret_key = '<my_secret_key>'
config.default_from = '<my_email>'
end
config/application.rb
config.action_mailer.delivery_method = :mailjet_api
And this is action in my controller
def send_email_reserved
email = { :from_email => "<my_from_email>",
:from_name => "Dona Sky",
:subject => "Hello",
:text_part => "Hi",
:recipients => [{:email => "<my_to_email>"}] }
test = Mailjet::Send.create(email)
p test.attributes['Sent']
end
When I called the action, it showed the error
NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}>
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in `type_for_extension'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in `type_for_extension'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block (2 levels) in stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `map'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:286:in `block in stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `each'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `inject'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `stringify_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in `make_headers'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in `initialize'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:67:in `handle_api_call'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/connection.rb:47:in `post'
from /Users/Dona/.rvm/gems/ruby-2.2.2/gems/mailjet-1.3.8/lib/mailjet/resource.rb:215:in `save'
This is a dependency issue. Try adding this : gem rest-client '~>1.6.9' to your Gemfile and run bundle update
This seemed to be a flickering sort of a bug for a while,but now it's appearing consistently: when I run RSpec on a fairly simple ApplicationHelper spec, I get the following error:
% rspec --backtrace
1) ApplicationHelper renders Markdown from plain text
Failure/Error: expect(helper.md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
NameError:
undefined local variable or method `helper' for #<RSpec::ExampleGroups::ApplicationHelper_2:0x000001248d1218>
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-expectations-0f7b78587ab4/lib/rspec/matchers.rb:903:in `method_missing'
# ./spec/helpers/application_helper_spec.rb:4:in `block (2 levels) in <top (required)>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:148:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:148:in `block in run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `call'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `block (2 levels) in <class:Procsy>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-rails-480b173c9ad6/lib/rspec/rails/adapters.rb:67:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:292:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:292:in `instance_exec'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `call'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:208:in `block (2 levels) in <class:Procsy>'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:432:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/hooks.rb:485:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:301:in `with_around_example_hooks'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example.rb:145:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:490:in `map'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:490:in `run_examples'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/example_group.rb:457:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `map'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/reporter.rb:49:in `report'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:86:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:70:in `run'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/lib/rspec/core/runner.rb:38:in `invoke'
# /Users/danielsh/.rvm/gems/ruby-2.1.1#project-staging-ng/bundler/gems/rspec-core-4219c4786f6f/exe/rspec:4:in `<top (required)>'
# /Users/danielsh/Dropbox/Project/Websites/Angular/bin/rspec:20:in `load'
# /Users/danielsh/Dropbox/Project/Websites/Angular/bin/rspec:20:in `<main>'
Here's the complete spec file (spec_helper is included as part of my .rspec file):
describe ApplicationHelper do
it 'renders Markdown from plain text' do
plaintext = '# Header'
expect(helper.md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
end
end
This was working up until recently, but I'm not certain what I could have done to break such a basic feature. I'm using edge versions of Rails and RSpec, but didn't see anything in their git repos to suggest that helper had been deprecated---and running rails g helper foo still generates a foo_helper_spec.rb file with instructions indicating that helper contains the helper itself. If anyone has any ideas, I'd be grateful for them!
I created a new Rails project with a fresh RSpec installation, and it led me to the problem. Apparently one of the recent betas introduced a configuration directive called config.infer_spec_type_from_file_location! that was missing from my slightly older spec_helper file; without it, RSpec wasn't guessing the spec type and mixing in the associated methods. Beware breaking changes!
add :type => :helper
so your code should look like
describe ApplicationHelper, type: :helper do
...
end
That's a weird error !! are you sure you required spec_helper in your spec ?
Anyway you could try without the helper method:
First you should first add to /spec/spec_helper.rb the following:
RSpec.configure do |config|
...
config.include ApplicationHelper
end
Then test without helper , so it will be:
describe ApplicationHelper do
it 'renders Markdown from plain text' do
plaintext = '# Header'
expect(md(plaintext)).to eq("<h1 id=\"header\">Header</h1>\n")
end
end
From the backtrace, it doesn't look like you're using the rspec-rails gem - just rspec-core and rspec-expectations.
rspec-rails is what provides the helper method to your helper specs. From inside a spec in my codebase:
(rdb:1) self.method(:helper).source_location
["/home/becky/.gem/ruby/2.0.0/gems/rspec-rails-2.14.1/lib/rspec/rails/example/helper_example_group.rb", 19]
I'm not new to DynamoDB, but I'm new to DynamoID gem.
I can't achieve to make it work since I get the following error :
/aws-sdk-1.28.1/lib/aws/core/client.rb:366:in `return_or_raise': The action or operation requested is invalid. Verify that the action is typed correctly. (AWS::DynamoDB::Errors::InvalidAction)
/aws-sdk-1.28.1/lib/aws/core/client.rb:467:in `client_request'
(eval):3:in `list_tables'
/aws-sdk-1.28.1/lib/aws/dynamo_db/table_collection.rb:121:in `_each_item'
/aws-sdk-1.28.1/lib/aws/core/collection/with_limit_and_next_token.rb:54:in `_each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:80:in `each_batch'
/aws-sdk-1.28.1/lib/aws/core/collection.rb:47:in `each'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `collect'
/dynamoid-0.7.1/lib/dynamoid/adapter/aws_sdk.rb:185:in `list_tables'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (3 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:146:in `block (2 levels) in <module:Adapter>'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `block in reconnect!'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:39:in `benchmark'
/dynamoid-0.7.1/lib/dynamoid/adapter.rb:25:in `reconnect!'
/dynamoid-0.7.1/lib/dynamoid.rb:35:in `configure'
app/config/initializers/dynamoid.rb:1:in `<top (required)>'
It seems that list_tables doesn't exist, but it's a method of the AWS Ruby SDK
My model is very simple :
class Interaction
include Dynamoid::Document
table :name => :interactions, :key => :from, :read_capacity => 1, :write_capacity => 1
end
Could anybody help?
Cheers,
Emmanuel
I got error on RSpec running my helper test on Rails Main Application (with further plugins)
1) MenuHelper maintence menu
Failure/Error: before { menu = build_menu_maintence() }
NameError:
undefined local variable or method `main_app' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007f92f561f280>
# ./app/helpers/menu_helper.rb:37:in `eval'
# (eval):1:in `block in build_menu_items'
# ./app/helpers/menu_helper.rb:37:in `eval'
# ./app/helpers/menu_helper.rb:37:in `block in build_menu_items'
# ./app/helpers/menu_helper.rb:23:in `each'
# ./app/helpers/menu_helper.rb:23:in `build_menu_items'
# ./app/helpers/menu_helper.rb:15:in `build_menu'
# ./app/helpers/menu_helper.rb:48:in `build_menu_maintence'
# ./spec/helpers/menu_helper_spec.rb:11:in `block (3 levels) in <top (required)>'
I had success with the following in a mountable Engine:
def main_app
Rails.application.class.routes.url_helpers
end
main_app.root_path