Proc的undefined方法`unbind'(但是我没有unbind方法)

时间:2015-01-15 13:40:16

标签: ruby-on-rails

进行基本帮助测试:

require 'rails_helper'

describe BuilderHelper do
  ...
  describe 'press events classes' do
    let(:account) { create(:candidate_profile).account }

    before { allow_any_instance_of(Object).to receive(:current_account).and_return account }

    specify do
      expect_any_instance_of(PublicPage).to receive(:show_press?).and_return true
      expect_any_instance_of(PublicPage).to receive(:show_events?).and_return true
      expect(press_events_classes(account)).to eq 'section'
    end
    ...
  end
  ...
end

它给出了一个奇怪的错误:

 Failure/Error: before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
     NoMethodError:
       undefined method `unbind' for #<Proc:0x00000009803640>
     # ./spec/helpers/builder_helper_spec.rb:27:in `block (3 levels) in <top (required)>'
     # ./spec/support/vcr.rb:16:in `block (2 levels) in <top (required)>'
     (that's it, that's the whole error log)

因此错误发生在before块中。 问题是我没有&#34;解开&#34;任何方法。 我查看了Rails回购 - 它似乎也没有任何东西。 不知道问题是什么。任何人都可以帮助到哪里看看吗?


更新

好的,感谢评论我得到了这个:

 1) BuilderHelper press events classes 
     Failure/Error: before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
     NoMethodError:
       undefined method `unbind' for #<Proc:0x000000025ff9e0>
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:372:in `original_unbound_method_handle_from_ancestor_for'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:355:in `original_method_handle_for'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:28:in `original_method'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:57:in `define_proxy_method'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:50:in `configure_method'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:150:in `add_stub'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:112:in `add_stub'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:38:in `block in stub'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:81:in `map'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:81:in `perform_proxying'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:37:in `stub'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:88:in `setup_method_substitute'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:81:in `setup_any_instance_method_substitute'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:49:in `setup_any_instance_allowance'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/targets.rb:45:in `define_matcher'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/targets.rb:14:in `block in delegate_to'
     # ./spec/helpers/builder_helper_spec.rb:27:in `block (3 levels) in <top (required)>'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:349:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `block in run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `each'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:340:in `run_before_example'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:147:in `block in run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-rails-3.0.2/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
     # ./spec/support/vcr.rb:16:in `block (2 levels) in <top (required)>'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:432:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:145:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:494:in `block in run_examples'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `map'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `run_examples'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:457:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `block in run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `map'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `map'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:54:in `report'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:108:in `run_specs'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:86:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
     # /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
     # /home/dell/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `load'
     # /home/dell/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `<main>'
     # /home/dell/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
     # /home/dell/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'

仍然不确定该怎么做。


更新

通过替换此解决:

before { allow_any_instance_of(Object).to receive(:current_account).and_return account }

有了这个:

before { allow_any_instance_of(BuilderHelper).to receive(:current_account).and_return account }

1 个答案:

答案 0 :(得分:0)

所以我最好的猜测基于这个很难说,但我发生的事实上我实际上已经找到了查找并返回了一个proc对象。

let(:record) { create :record } # This is a Proc
allow(Object).to receive(:find).and_return(record)
allow_any_instance_of(Object).to receive(:update) # This calls unbind

遗憾地试图找出第一个存根发生的位置。但我敢打赌它在你的代码中。