2

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

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

任何对替代语法的建议将不胜感激!

4

1 回答 1

0

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

于 2013-10-06T01:40:23.367 回答