Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created August 29, 2011 15:32
Show Gist options
  • Save nickhoffman/1178636 to your computer and use it in GitHub Desktop.
Save nickhoffman/1178636 to your computer and use it in GitHub Desktop.
Why does this error occur in the spec?: undefined method `each_pair'
$ bundle exec rspec --fail-fast -b spec/models/spreadsheet_importer_spec.rb
No examples were matched by {:focus=>true}, running all
F
Failures:
1) SpreadsheetImporter instance variables has a reader for @catalog
Failure/Error: @importer = SpreadsheetImporter.new @catalog, @excel, @photos_dir
NoMethodError:
undefined method `each_pair' for #<Catalog:0xb0475bc>
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.4/lib/active_model/attribute_methods.rb:364:in `method_missing'
# /usr/local/rvm/gems/ruby-1.9.2-p0/bundler/gems/mongoid-c4675a987925/lib/mongoid/attributes.rb:151:in `method_missing'
# /usr/local/rvm/gems/ruby-1.9.2-p0/bundler/gems/mongoid-c4675a987925/lib/mongoid/matchers.rb:20:in `matches?'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/argument_matchers.rb:107:in `=='
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/argument_expectation.rb:45:in `=='
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/argument_expectation.rb:45:in `matchers_match?'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/argument_expectation.rb:37:in `args_match?'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/message_expectation.rb:102:in `matches?'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb:149:in `block in find_matching_method_stub'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb:149:in `each'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb:149:in `find'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb:149:in `find_matching_method_stub'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/proxy.rb:96:in `message_received'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-mocks-2.5.0/lib/rspec/mocks/method_double.rb:79:in `new'
# ./app/models/spreadsheet_importer.rb:15:in `initialize'
# ./spec/models/spreadsheet_importer_spec.rb:25:in `new'
# ./spec/models/spreadsheet_importer_spec.rb:25:in `block (2 levels) in <top (required)>'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `instance_eval'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `run_in'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `block in run_all'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `each'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `run_all'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:110:in `run_hook'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `each'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:144:in `run_before_each'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:106:in `with_around_hooks'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:46:in `block in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `catch'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `with_pending_capture'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:45:in `run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:262:in `block in run_examples'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `map'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `run_examples'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:232:in `run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `block in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `map'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:233:in `run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `map'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/reporter.rb:12:in `report'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:24:in `run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.5.2/lib/rspec/monkey/spork/test_framework/rspec.rb:4:in `run_tests'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/run_strategy/forking.rb:13:in `block in run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/forker.rb:21:in `block in initialize'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/forker.rb:18:in `fork'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/forker.rb:18:in `initialize'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/run_strategy/forking.rb:9:in `new'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/run_strategy/forking.rb:9:in `run'
# /usr/local/rvm/gems/ruby-1.9.2-p0/gems/spork-0.9.0.rc4/lib/spork/server.rb:48:in `run'
# /usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
# /usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
# /usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
# /usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
# /usr/local/rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Finished in 0.48365 seconds
1 example, 1 failure
$
class SpreadsheetImporter
extend ActiveModel::Naming
extend ActiveModel::Translation
attr_reader :catalog
attr_reader :spreadsheet
attr_reader :errors
attr_reader :photos_dir
def initialize(catalog, spreadsheet, photos_dir)
@catalog = catalog
@spreadsheet = spreadsheet
@photos_dir = photos_dir
@errors = ActiveModel::Errors.new self
@products_importer = SpreadsheetImporter::Products.new catalog, spreadsheet
end
require 'spec_helper'
describe SpreadsheetImporter do
before :each do
@catalog = Catalog.new do |c|
c.name = 'Test Catalog'
c.number = 'TC'
c.product_properties = [
Property.new(:short_name => 'Manufacturer', :type => :string),
Property.new(:short_name => 'Packaging Text', :type => :paragraph),
Property.new(:short_name => 'Strength', :type => :integer),
Property.new(:short_name => 'MSRP (USD)', :type => :decimal),
Property.new(:short_name => 'Release Date', :type => :date),
Property.new(:short_name => 'Package Type', :type => :string_collection),
]
end
@valid_excel = 'spec/support/catalog_spreadsheets/valid.xls'
@excel = Excel.new @valid_excel
@photos_dir = Rails.root.join('spec', 'support', 'catalog_spreadsheets', 'photos').to_s
@products_importer = mock SpreadsheetImporter::Products
SpreadsheetImporter::Products.stub(:new).with(@catalog, @excel).and_return @products_importer
@importer = SpreadsheetImporter.new @catalog, @excel, @photos_dir
end
describe 'instance variables' do
it 'has a reader for @catalog' do
@importer.catalog.should be @importer.instance_variable_get :@catalog
end
@atomical
Copy link

Did you ever find out the solution to this problem?

@nickhoffman
Copy link
Author

@atomical Unfortunately, this is from so long ago that I can't remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment