RSpec视图测试使用RR失败未定义的方法存根



我正在使用Rails 3.1, RSpec 2.6和rr 1.0.4,我得到一个NoMethodError:

undefined method `stub' for #<Activity:0x007faa90996190>

我正试图利用下面的RSpec测试来测试我的"Activities"show。haml的观点。如果我改变spec_helper。使用RSpec代替rr来模拟,那么测试就通过了。我试过改变代码的语法,但没有成功。

我发现几个网站说RSpec和rr不能很好地一起玩,一个人提供了这个rpspec -rr解决方案,但对我不起作用。

这是我的show.haml_spec.rb

require 'spec_helper'
describe "activities/show.haml" do
  before(:each) do
    @activity = assign(:activity, stub_model(Activity))
  end
  it "renders attributes in .haml" do
    render
  end
end

这是我的Eclipse编译器使用Aptana Studio

的输出
Failures:
  1) activities/show.haml renders attributes in .haml
     Failure/Error: @activity = assign(:activity, stub_model(Activity))
     NoMethodError:
       undefined method `stub' for #<Activity:0x007faa90996190>
     # ./spec/views/activities/show.haml_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.15479 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/views/activities/show.haml_spec.rb:8 # activities/show.haml renders attributes in .haml

任何关于替代语法的建议都将非常感谢!!

注意,从RR 1.0.5(2013年3月28日发布)开始,这个问题应该不再存在了——RR与RSpec 2完全兼容。

最新更新