Ruby on rails 帮助者不应该';行不通

Ruby on rails 帮助者不应该';行不通,ruby-on-rails,testing,rspec,shoulda,Ruby On Rails,Testing,Rspec,Shoulda,我有一个规范: require 'spec_helper' # hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises. include Shoulda::ActionController::Matchers describe CategoriesController do include Devise::TestHel

我有一个规范:

require 'spec_helper'

# hmm... I need to include it here because if I include it inside describe block `method_missing` exception raises.
include Shoulda::ActionController::Matchers

describe CategoriesController do
  include Devise::TestHelpers

  render_views

  context "new should render template :new" do
    setup do
      sign_in :user
      get :new
    end

    should render_template(:new)
  end
end
当我运行
rake spec
时,我看到了这一点(但如果我将上下文更改为它,并将
setup
块内容移动到
it
块,所有工作都正常):

我使用的是Rails3。rspec/shoulda/factory_girl通过GEM文件中的此代码包含在应用程序中:

group :test, :development do
  gem 'autotest'
  gem 'factory_girl'
  gem "shoulda"
  gem "rspec-rails", ">= 2.0.0.beta.20"
end

如果我没有弄错的话,我使用了Shoulda,我认为语法是正确的

should_render_template(:new)
而不是

should render_template(:new)

这解释了0个测试,0个断言…

如果我没有弄错的话,我使用了Shoulda,我认为语法是正确的

should_render_template(:new)
而不是

should render_template(:new)

这解释了0个测试,0个断言…

我很确定错误是因为您没有像这样将您的shoulda断言包装到
it
块中:

it { should render_template(:new) }
当将Shoulda与RSpec一起使用时,这是必需的


应该单独呈现_模板(:new)
将与Test::Unit一起工作。

我很确定错误是因为您没有像这样将shoulda断言包装在
it
块中:

it { should render_template(:new) }
当将Shoulda与RSpec一起使用时,这是必需的


应该单独呈现模板(:new)
将与Test::Unit一起工作。

这也不起作用。我得到错误“undefined method'should_render_template”这是不推荐使用的语法,至少应该是2.11.x这也不起作用。我收到错误“undefined method'should_render_template”这是至少在shoulda 2.11.xYes中不推荐使用的语法,但我需要在
上下文
块中运行shoulda helpers。可能吗?是的,在一个上下文块中可以有任意多个断言。您发布的CategoriesController规范很好,只需在
it
块中包装
就可以呈现模板(:new)
,并且应该可以工作。是的,但我需要在
上下文
块中运行shoulda helpers。可能吗?是的,在一个上下文块中可以有任意多个断言。您发布的CategoriesController规范很好,只需在
it
块中包装
就可以呈现模板(:new)
,并且应该可以工作。