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

时间:2011-12-24 01:38:54

标签: ruby-on-rails-3.1 rspec2 rspec-rails rr

我正在使用Rails 3.1,RSpec 2.6和rr 1.0.4,我得到NoM​​ethodError:

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

我正在尝试使用下面的RSpec测试来测试我的“活动”show.haml视图。如果我更改我的spec_helper.rb文件以使用RSpec而不是rr,则测试通过。我试过改变代码的语法但没有成功。

我发现有几个网站声称RSpec和rr没有“很好地协同工作,而且有一个人提供了这个rpsec-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

非常感谢对替代语法的任何建议!!

1 个答案:

答案 0 :(得分:0)

请注意,自RR 1.0.5(2013年3月28日发布)以来,此问题不再存在 - RR与RSpec 2完全兼容。