0

我的很多规范都失败了,并给了我关于 __mock_proxy() 的错误消息:

$ rspec spec/helpers/liaisons_helper_spec.rb
WARNING: Cucumber-rails required outside of env.rb.  The rest of loading is being defered until env.rb is called.
  To avoid this warning, move 'gem cucumber-rails' under only group :test in your Gemfile
FF

Failures:

  1) LiaisonsHelper hrefs_of_email_addresses_for_liaison to enumerate email_addresses as RESTful links
     Failure/Error: email_address = mock_model(EmailAddress)
     Mocha::ExpectationError:
       unexpected invocation: #<Mock:EmailAddress_1001>.__mock_proxy()
       unsatisfied expectations:
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.id(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.blank?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.valid?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.marked_for_destruction?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.destroyed?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:EmailAddress_1001>.persisted?(any_parameters)
     # ./spec/helpers/liaisons_helper_spec.rb:6:in `block (3 levels) in <top (required)>'

  2) LiaisonsHelper hrefs_of_phone_numbers_for_liaison to enumerate phone_numbers as RESTful links
     Failure/Error: phone_number = mock_model(PhoneNumber)
     Mocha::ExpectationError:
       unexpected invocation: #<Mock:PhoneNumber_1002>.__mock_proxy()
       unsatisfied expectations:
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.id(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.blank?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.valid?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.marked_for_destruction?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.destroyed?(any_parameters)
       - expected exactly once, not yet invoked: #<Mock:PhoneNumber_1002>.persisted?(any_parameters)
     # ./spec/helpers/liaisons_helper_spec.rb:19:in `block (3 levels) in <top (required)>'

我正在运行 Rails 3.1.4 和 Ruby 1.9.2,并且正在使用这些 gem:

$ bundle list | grep mocha
  * mocha (0.10.5)
  * rspec-rails-mocha (0.3.1)
$ bundle list | grep rspec
  * rspec (2.8.0)
  * rspec-apotomo (0.9.6)
  * rspec-cells (0.1.2)
  * rspec-core (2.8.0)
  * rspec-expectations (2.8.0)
  * rspec-mocks (2.8.0)
  * rspec-rails (2.8.1)
  * rspec-rails-mocha (0.3.1)

我发现了一些关于人们遇到相同错误的报告,包括github 上的这个,但它们似乎都已过时或不包含解决方案。


编辑:这些规格适用于我同事的电脑,但不适用于我的电脑。看起来差异与包含的顺序RSpec::Rails::Mocha有关RSpec::Rails::Mocks-RSpec::Rails::Mocha必须最后包含。

我制作了一个测试规范,其输出显示如下:

describe 'test' do
  it 'test' do
    m = self.method(:mock_model)
    p m
    p m.source_location
    p self.class.included_modules.map(&:to_s).grep(/Moc/)
  end
end

在我同事的计算机(规范工作的地方)上,它产生了以下输出:

#<Method: RSpec::Core::ExampleGroup::Nested_1::Nested_1(RSpec::Rails::Mocha)#mock_model>
["/Users/username/.rvm/gems/ruby-1.9.2-p290-patched@development3/gems/rspec-rails-mocha-0.3.1/lib/rspec/rails/mocha.rb", 59]
["RSpec::Rails::Mocha", "RSpec::Rails::Mocks", "RSpec::Core::MockFrameworkAdapter", "Mocha::API", "Mocha::ParameterMatchers", "Mocha::ObjectMethods"]

在我的电脑上(规范不起作用),它产生了这个输出:

#<Method: RSpec::Core::ExampleGroup::Nested_1::Nested_1(RSpec::Rails::Mocks)#mock_model>
["/Users/username/.rvm/gems/ruby-1.9.2-p290-patched@development3/gems/rspec-rails-2.9.0/lib/rspec/rails/mocks.rb", 67]
["RSpec::Rails::Mocks", "RSpec::Rails::Mocha", "RSpec::Core::MockFrameworkAdapter", "Mocha::API", "Mocha::ParameterMatchers", "Mocha::ObjectMethods"]
4

1 回答 1

0

这可以通过添加:require => falserspec-rails-mochaGemfile 中的行来解决。

于 2012-04-12T13:53:16.537 回答