【问题标题】:RSpec view test using RR failing - undefined method stub使用 RR 失败的 RSpec 视图测试 - 未定义的方法存根
【发布时间】:2011-12-24 01:38:53
【问题描述】:

我正在使用 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

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多