Testing ruby (not rails) script with cucumber on Mac OS X - ruby

I am trying to get cucumber working on my Mac for testing a ruby script. I use cucumber with rails and have never had an issue setting it up there, but seem to be having quite an issue creating it just for a ruby script that I want to test.
Script background: I have created a script that serves mysql data via a TCPServer connection and I want to be able to test this functionality. So ideally I launch the script so that it accepts incoming connections and depending on what I am attempting to get to it presents an error or the data end point.
Here is what I have and the error is below the settings:
features/support/env.rb
require_relative File.expand_path('../../../lib/requirements',FILE)
require "capybara/cucumber"
require 'capybara/dsl'
require "rspec"
# Capybara.default_driver = :selenium
Capybara.app_host = 'http://localhost:7125'
World(Capybara.app = "Api")
World(Capybara::DSL)
World(RSpec::Matchers)
features/rmws.feature
Feature: Test conversion of mysql output to JSON
Scenario:
Given the index page can be reached
And There is MYSQL data
When converted to hash
And and /mysql location is hit
Then the data is show in JSON
features/step_definitions/rwms_step_definitions.rb
Given(/^the index page can be reached$/) do
visit 'http://localhost:7125'
expect(page).to have_content 'This is the index page'
end
Given(/^There is MYSQL data$/) do
pending # express the regexp above with the code you wish you had
end
When(/^converted to hash$/) do
pending # express the regexp above with the code you wish you had
end
When(/^and \/mysql location is hit$/) do
pending # express the regexp above with the code you wish you had
end
Then(/^the data is show in JSON$/) do
pending # express the regexp above with the code you wish you had
end
Output
$ cucumber
Feature: Test conversion of mysql output to JSON
Scenario: # features/rmws.feature:3
wrong argument type String (expected Module) (TypeError)
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `extend'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:150:in `block in extend_world'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:149:in `extend_world'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:94:in `begin_rb_scenario'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/rb_support/rb_language.rb:128:in `begin_scenario'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:14:in `before'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:112:in `block in fire_hook'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:111:in `fire_hook'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:107:in `before'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:98:in `before_and_after'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:82:in `block in with_hooks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/language_support/language_methods.rb:8:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `call'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime/support_code.rb:123:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:94:in `around'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:81:in `with_hooks'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:13:in `execute'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:32:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/scenario.rb:31:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:38:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/feature.rb:37:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:28:in `block in accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:17:in `each'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/features.rb:27:in `accept'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/runtime.rb:49:in `run!'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/lib/cucumber/cli/main.rb:47:in `execute!'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-1.3.11/bin/cucumber:13:in `<top (required)>'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `load'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/cucumber:23:in `<main>'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
/Users/lovell/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'
$

You could use rake to run cucumber tests, I use it for a gem that I wrote. You can find additional doc here
require 'bundler'
require 'rake/clean'
require 'rake/testtask'
require 'cucumber'
require 'cucumber/rake/task'
require 'rspec/core/rake_task'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
t.fork = false
end

Run cucumber --init to get the testing suite set up.

Related

How to fix ActiveRecord::DangerousAttributeError when checking pending migration in RSpec spec_helper?

Okay so this is a new one. RSPec. Rails 4.
This line is in my spec_helper.rb:
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
When I run a simple test (on an ActiveRecord model):
it { should respond_to :activity }
I get the following error & trace:
/Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord 4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?': version is defined by Active Record (ActiveRecord::DangerousAttributeError)
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `synchronize'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:793:in `current_version'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
from /Users/dev/.rvm/gems/ruby-2.0.0-p247#projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
from /projects/subset_of_projects/this_project_group/projectname/spec/spec_helper.rb:17:in `<top (required)>'
I'd added the paper_trail gem but not run the install/migrations. Simple and obvious really. But it wasn't an error I'd seen before so I'll post this so others who might run into it can check the obvious before wasting a long time on this.

rubygems.rb:550:in `initialize': not in gzip format (Zlib::GzipFile::Error)

when i try to run the command 'bundle install' or installing particular gem then ot in gzip format (Zlib::GzipFile::Error) occurs.
i have done googling and find some of the answers
like removing cache ,bundle packages but all fail in my case
i am using rails 3.2.11 and ruby 1.8.7
the code of rubygems line arround 500 is
def self.gunzip(data)
require 'stringio'
require 'zlib'
data = StringIO.new data
Zlib::GzipReader.new(data).read
end
##
# Zlib::GzipWriter wrapper that zips +data+.
def self.gzip(data)
require 'stringio'
require 'zlib'
zipped = StringIO.new
Zlib::GzipWriter.wrap zipped do |io| io.write data end
zipped.string
end
while error in console is
Unfortunately, a fatal error has occurred. Please see the Bundler troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/usr/lib/ruby/site_ruby/1.8/rubygems.rb:550:in `initialize': not in gzip format (Zlib::GzipFile::Error)
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:550:in `new'
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:550:in `gunzip'
from /usr/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:177:in `fetch_path'
from /usr/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:270:in `load_specs'
from /usr/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:243:in `list'
from /usr/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:239:in `each'
from /usr/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:239:in `list'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:104:in `fetch_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:117:in `fetch_all_remote_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/fetcher.rb:262:in `fetch_all_remote_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/fetcher.rb:116:in `specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:235:in `remote_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:235:in `each'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:235:in `remote_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:163:in `fetch_specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:67:in `specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:192:in `index'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `each'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `index'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/index.rb:9:in `build'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:185:in `index'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:179:in `resolve'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/definition.rb:109:in `resolve_remotely!'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:83:in `run'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:14:in `install'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/cli.rb:320:in `update'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `__send__'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/bin/bundle:20
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
from /usr/lib64/ruby/gems/1.8/gems/bundler-1.3.5/bin/bundle:20
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19
Hope this information will be enough for providing me the right way for solution

Thin fails spawning workers when running on EventMachine

I have a ruby web- / data-server application which is built on a Sinatra foundation. I'm adding EventMachine and em-websocket so that I can have async data transfer connections.
#! /usr/bin/env ruby
require 'yajl'
require 'json'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
require './Actors/DataProvider.rb'
my_host = '10.2.56.87'
my_web_port = '4004'
my_web_sock = '8008'
EventMachine.epoll # choose kernel epoll over select for deterministic execution under load
EventMachine.run do
class SinatraApp < Sinatra::Base
configure do
set :bind, '10.2.56.87'
set :port, '4004'
end
encoder = Yajl::Encoder.new
communicator = DataProvider.new( encoder )
get '/' do
redirect '/index-work.html'
end
before do
content_type 'application/json'
end
post '/auth' do
end
post '/data/:id' do
puts 'got d i '
end
end
EventMachine::WebSocket.start( :host => my_host, :port => my_web_sock ) do | ws |
ws.onopen do
end
ws.onmessage do
end
ws.onclose do
end
end
begin
SinatraApp.run!
rescue => ex
puts "#{ ex.class}: #{ ex.message }"
end
end
The Thin server worked fine when just serving Sinatra, but now that I've added the EM foundation the following occurs:
/usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:192:in `block (2 levels) in start': undefined method `attach_server' for EventMachine:Module (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:30:in `block (2 levels) in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:23:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `work'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:129:in `block (2 levels) in spawn_missing_workers'
from (eval):6:in `block in fork'
from (eval):6:in `fork'
from (eval):6:in `fork'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:126:in `block in spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `times'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:44:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:37:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:187:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/sinatra-1.3.3/lib/sinatra/base.rb:1350:in `run!'
from /home/devel/ISF_Server/server-work.rb:122:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /home/devel/ISF_Server/server-work.rb:15:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_load'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_program'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide:118:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
I do notice that the Thin gem was recently updated, but EM has not been. That's my next point of inquiry. Somebody else posted that Thin should not be run from within EM.run block, but the example I am building from had it this way.
Okay. I corresponded with Marc-Andre Cournoyer directly. He says, first, don't spawn This (through Sinatra) inside an EM.run block.
Secondly, the error is generated from Thin 2 (pre) which requires the EventMachine live Edition, or gem eventmachine-le.
Mo' bettah now. :D

NoMethodError: undefined method `belong_to' for #<RSpec::Core::ExampleGroup::Nested_4:0xa05d2a0>

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

object.find fails in rakefile even though I'm including environment

I've got a rakefile with a cron job in it that accesses one of my models and then does a search on my database. I'm including my environment and see to be able to create my object, but when I try to run the "find" method, I get this error:
rake aborted!
undefined method `find' for #<Feeder:0x103611df0>
/Library/Ruby/Gems/1.8/gems/activemodel-3.0.4/lib/active_model/attribute_methods.rb:364:in `method_missing'
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/attribute_methods.rb:46:in `method_missing'
/Users/josh.kerr/Documents/Projects/joshkerr.jekyll/Rakefile:28
/Users/josh.kerr/Documents/Projects/joshkerr.jekyll/Rakefile:20:in `each'
/Users/josh.kerr/Documents/Projects/joshkerr.jekyll/Rakefile:20
/Users/josh.kerr/Documents/Projects/joshkerr.jekyll/Rakefile:18:in `each'
/Users/josh.kerr/Documents/Projects/joshkerr.jekyll/Rakefile:18
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Here is the code:
require 'rails/all'
require 'rake/clean'
require File.expand_path('../config/application', __FILE__)
require 'rubygems'
require 'sqlite3'
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
puts "Running cron at #{Time.now.strftime('%Y/%m/%d %H:%M:%S')}..."
require 'app/models/feeder'
num_feeds = 10
feedurls = ["http://twitter.com/statuses/user_timeline/2205491.rss","http://github.com/joshkerr.atom","http://gdata.youtube.com/feeds/base/users/joshkerr/uploads","http://api.flickr.com/services/feeds/photos_public.gne?id=95219360#N00&lang=en-us&format=rss_200","http://www.google.com/reader/public/atom/user%2F00755727578217480286%2Fstate%2Fcom.google%2Fbroadcast"]
feedurls.each do |feed|
rawfeed = Feedzirra::Feed.fetch_and_parse(feed)
for i in 0..num_feeds do
# Database call
fed = Feeder.new
fed.title = rawfeed.entries[i].title
fed.published = rawfeed.entries[i].published
fed.url = rawfeed.entries[i].url
fed.feed_id = rawfeed.entries[i].entry_id
fed.find(1) # <- FAILS HERE!!!
#if not fed.Find(1) then
if fed.url.include? "twitter.com" then
fed.feed_service="twitter"
elsif fed.url.include? "github.com" then
fed.feed_service="github"
elsif fed.url.include? "flickr.com" then
fed.feed_service="flickr"
elsif fed.url.include? "youtube.com" then
fed.feed_service="youtube"
elsif fed.feed_id.include? "google.com" then
fed.feed_service="reader"
else
fed.feed_service = "reader"
end
fed.save
#end
end
end
puts "Done creating feed"
puts "done."
end
find is a method on an ActiveRecord class, and is not defined on an instance of an ActiveRecord object. So, to find the Feeder with ID of 1, you'd call Feeder.find(1).
The other thing I noticed is this: the line task :cron => :environment means that the environment is already being loaded--this includes rails/all, rubygems (you're using Rails 3, which uses Bundler), sqlite3 (assuming it's in your Gemfile and you've run bundle install to generate your Gemfile.lock, and all your models. Try removing all the requires lines and see if your rake task still executes.

Resources