I found the following problem to use net/sftp:
undefined method `put_file' for #<Net::SFTP::Session:0x00000001b40298>
(NoMethodError)
sftp.rb:17:in `block in <main>': undefined method `put_file' for #<Net::SFTP::Session:0x00000000b70138> (NoMethodError)
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `call'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `block in do_version'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `each'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `do_version'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:909:in `when_channel_polled'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/channel.rb:311:in `call'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/channel.rb:311:in `process'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `block in preprocess'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `each'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `preprocess'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:197:in `process'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `block in loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:787:in `connect!'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp.rb:32:in `start'
from sftp.rb:16:in `<main>'
But the module could be loaded without problem:
2011.07.08|17:12:07~/lin/Ruby>irb
irb(main):001:0> require 'net/ssh'
=> true
irb(main):002:0> require 'net/sftp'
=> true
irb(main):003:0>
By the way, my RUBYLIB is:
2011.07.08|17:15:33~/lin/Ruby>echo $RUBYLIB
/opt/ruby/lib/ruby/1.9.1/
Thanks!
Dan
P.S:
require 'net/ssh'
require 'net/sftp'
host="localhost"
src_file="/etc/services"
dst_file="~/services"
Net::SFTP.start(host, ENV["USER"]) do |sftp|
sftp.put_file(src_file, dst_file)
end
......
Net::SFTP does not have a put_file method. See the full documentation for Net::SFTP.
Did you perhaps mean sftp.upload or sftp.upload!?
Check your version. Net::SFTP 2 doesn't have put_file anymore. Use upload instead.
Related
In my ruby 2.3.1, I get this error:
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/will_paginate-3.0.pre2/lib/will_paginate/railtie.rb:15:in `block in <class:Railtie>': uninitialized constant WillPaginate::Railtie::Forbidden (NameError)
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
from /home/bistipweb/config/environment.rb:5:in `<top (required)>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /home/bistipweb/config.ru:3:in `block in <main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /home/bistipweb/config.ru:in `new'
from /home/bistipweb/config.ru:in `<main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:78:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
My railtie.rb is:
require 'will_paginate'
require 'will_paginate/collection'
module WillPaginate
class Railtie < Rails::Railtie
initializer "will_paginate.active_record" do |app|
if defined? ::ActiveRecord
require 'will_paginate/finders/active_record'
WillPaginate::Finders::ActiveRecord.enable!
end
end
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
initializer "will_paginate.action_view" do |app|
require 'will_paginate/view_helpers/action_view'
ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
end
end
end
How can I fix it?
You don't have to add any initializer codes for hooking will_paginate into Rails project, if you are using recent will_paginate versions.
I see you are using 3.0.pre2 version, update it to 3.0.7 in your Gemfile, bundle update will_paginate and remove all the codes you added in railtie.rb, I think everything would be ok.
Try:
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
I do not find any reason for you to add railtie.rb file. I believe just adding the gem and using it in your view should work.
I'm randomly getting the following error message. Does anyone have any ideas what could be causing this?
NoMethodError (undefined method `slice!' for nil:NilClass):
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:274:in `read'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:248:in `block in read'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:236:in `io'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:247:in `read'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:112:in `block in call'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:217:in `block (2 levels) in process'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:353:in `ensure_connected'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:207:in `block in process'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:292:in `logging'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:206:in `process'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:112:in `call'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:789:in `block in get'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in `block in synchronize'
/usr/local/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:788:in `get'
vendor/bundle/ruby/2.1.0/gems/redis-store-1.1.4/lib/redis/store/interface.rb:5:in `get'
vendor/bundle/ruby/2.1.0/gems/redis-store-1.1.4/lib/redis/store/marshalling.rb:17:in `get'
vendor/bundle/ruby/2.1.0/gems/redis-activesupport-4.0.0/lib/active_support/cache/redis_store.rb:169:in `read_entry'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:312:in `block in read'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:548:in `instrument'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:311:in `read'
/var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/store.rb:34:in `get'
/var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/scoped_store.rb:13:in `fetch'
/var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/preferable_class_methods.rb:13:in `block in preference'
/var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/preferable.rb:43:in `get_preference'
vendor/bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/lib/spree/core/controller_helpers/ssl.rb:8:in `block (2 levels) in <module:SSL>'
The last place Spree is hit before calling redis-rb:
unless (val = #cache.read(key)).nil?
return val
end
where #cache = Rails.cache
UPDATE
I am using this gem with this SSL plugin, so the error may be related to the plugin.
The error happens when line = #sock.gets is nil. Here's the locals right after that is determined to be true.
[1] pry(#<Redis::Connection::Ruby>)> line
=> nil
[2] pry(#<Redis::Connection::Ruby>)> #sock
=> #<OpenSSL::SSL::SSLSocket:0x007fdab2688730
#callback_state=nil,
#context=
#<OpenSSL::SSL::SSLContext:0x007fdab2688758
#ca_file=nil,
#ca_path=nil,
#cert=nil,
#cert_store=nil,
#client_ca=nil,
#client_cert_cb=nil,
#extra_chain_cert=nil,
#key=nil,
#npn_protocols=nil,
#npn_select_cb=nil,
#options=nil,
#renegotiation_cb=nil,
#servername_cb=nil,
#session_get_cb=nil,
#session_id_context=nil,
#session_new_cb=nil,
#session_remove_cb=nil,
#timeout=nil,
#tmp_dh_callback=nil,
#verify_callback=nil,
#verify_depth=nil,
#verify_mode=nil>,
#eof=true,
#hostname=nil,
#io=#<Redis::Connection::TCPSocket:fd 11>,
#rbuffer="",
#sync=true,
#sync_close=false,
#wbuffer="">
[3] pry(#<Redis::Connection::Ruby>)> #sock.closed?
=> false
This looks like this could be an issue with the ruby redis client.
You could try downgrading a version and/or filing an issue for the redis team in the Github repository.
I was experimenting with the soundcloud gem and suddenly I always get an error with every request I make.
For example this following code:
require 'soundcloud'
client = SoundCloud.new(:client_id => MY_CLIENT_ID)
track_url = 'https://soundcloud.com/sohight/sohight-cheevy-money-is-love-out-now'
track = client.get('/resolve', :url => track_url)
puts track.genre
Anyone knows why I get this error?
/Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:33:in `normalize_param': uninitialized constant HTTParty::HashConversions::ERB (NameError)
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `block in to_params'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `each'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `map'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/hash_conversions.rb:15:in `to_params'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:148:in `normalize_query'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:180:in `query_string'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:70:in `uri'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:157:in `setup_raw_request'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty/request.rb:98:in `perform'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty.rb:521:in `perform_request'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.4/lib/httparty.rb:459:in `get'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:27:in `block in get'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:145:in `call'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:145:in `handle_response'
from /Users/angel/.rvm/gems/ruby-2.2.0/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:26:in `get'
from sound.rb:9:in `<main>'
Possibly a bug in HTTParty.
Line 33 of hash_conversions.rb:
param << "#{key}=#{ERB::Util.url_encode(value.to_s)}&"
Put this at the top of your script and try again:
require 'erb'
I found another similar question and think I'm following the referenced directions from here but am still coming across this error.
As per the instructions I'm calling Mongoid.load!("path/to/your/mongoid.yml") in my ruby script, so I don't think it's that.
Maybe, as per the error message coming from inflector, it's an issue with how I'm defining CarrierDomain. I'm referencing a rails model from the Sinatra script. It's in a model file called carrier_domain.rb and the class is defined as CarrierDomain (class CarrierDomain). In fact, here is the entire class definition (it's a little one):
class CarrierDomain
include Mongoid::Document
embedded_in :carrier
field :country
field :name
field :prefix, default: ''
end
Here's the error message I'm getting:
/Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant CarrierDomain (NameError)
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/metadata.rb:606:in `klass'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builder.rb:39:in `klass'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:25:in `block in build'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:23:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/builders/embedded/many.rb:23:in `build'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:43:in `create_relation'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:26:in `__build__'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:156:in `block (3 levels) in getter'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/threaded/lifecycle.rb:125:in `_loading'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:156:in `block (2 levels) in getter'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/relations/accessors.rb:155:in `block in getter'
from /opt/cmf/app/models/carrier.rb:120:in `to_email_addresses'
from mta_connector.rb:151:in `block in <main>'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:645:in `yield_document'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:134:in `block (2 levels) in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:78:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/cursor.rb:26:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:77:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.2.7/lib/moped/query.rb:77:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:133:in `block in each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:604:in `selecting'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual/mongo.rb:132:in `each'
from /Users/arigold/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.10/lib/mongoid/contextual.rb:18:in `each'
from mta_connector.rb:139:in `<main>'
I had to explicitly require 'carrier_domain' in my Sinatra script.
I had thought that it would know to get the file, since it worked in the rails console (that is, I didn't need to require it in the rails console). Hmm.
Anyhoo, adding require 'carrier_domain' (i.e. the uninitialized constant) to my Sinatra script worked.
So this is kind of baffling me as I can't quite figure out why it's happening. This only happens on my laptop (Ubuntu 11.04), and not elsewhere. I just seem to have something weird with the setup on this one computer.
I keep getting the following error when I run my specs:
be rake spec
Gives me:
NoMethodError: undefined method `belong_to' for #<RSpec::Core::ExampleGroup::Nested_4:0xb4eb2e4>
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-expectations-2.6.0/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
/home/tom/work/ruby/litdistco-sales/spec/models/sales_item_spec.rb:5:in `block (2 levels) in <top (required)>'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `block in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:45:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:294:in `block in run_examples'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `block in run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'
/home/tom/.rvm/gems/ruby-1.9.2-p290#litdistco/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:11:in `block in autorun'
Here are the relevant lines from my spec file that generates the complaint:
describe SalesItem do
it { should belong_to(:publisher) }
it { should belong_to(:invoice) }
I'm running Rails 3.1.0. Here is ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Any tips /thoughts/ideas recommendations greatly appreciated.
Try adding this in your rails_helper.rb
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
RSpec core does not have such matcher. It looks like shoulda-matchers. Just make sure that it's installed and loaded in your spec_helper
I was having a hard time with this for awhile and then changed my spec from:
describe ModelName do
it { should belong_to(:model)}
end
to:
RSpec.describe ModelName, type: :model do
it { should belong_to(:model)}
end
and it suddenly worked
You can write specs like this
describe SalesItem do
describe "Associations" do
it "belongs_to publisher" do
assc = described_class.reflect_on_association(:publisher)
expect(assc.macro).to eq :belongs_to
end
end
end