作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Rails3 与 rspec 和 Shoulda 一起使用。我有以下规范
describe PagesController, "on GET to show while logged off" do
before(:each) do
@site = Factory.create(:site)
@site.domains << Factory.create(:domain)
@site.save!
@site.pages << Factory.create(:page)
@site.menus << Factory.create(:menu, {:site=>@site, :is_visible=>true})
@site.menus << Factory.create(:menu, {:site=>@site, :is_visible=>true})
@site.menus << Factory.create(:menu, {:is_visible=>false, :site=>@site})
get :show
end
it { should render_template(:show) }
it { should render_template('layouts/2col') }
it { should assign_to(:site) }
it { should assign_to(:site).with(@site) }
it { should assign_to(:site).with(@site) }
it { should assign_to(:page).with(@site.pages[0])}
it "show visible menu_items only" do
assert assigns[:menu_items].length == 2
end
end
这是我的 gem 文件
group :development, :test do
gem 'autotest'
gem 'factory_girl'
gem 'rspec', '>=2.0.0.beta.19'
gem 'rspec-rails', '>=2.0.0.beta.17'
gem 'shoulda'
end
这是我的spec_helper
require 'rspec/rails'
require 'shoulda'
require 'shoulda/integrations/rspec2'
require 'authlogic/test_case'
require 'factory_girl
好吧,到目前为止,一切都非常接近我之前看到的情况,但是每当我运行测试时,我都会收到如下错误
1) PagesController on GET to show while logged off
Failure/Error: it { should assign_to(:site) }
Expected action to assign a value for @site
# ./spec/controllers/pages_controller_spec.rb:19
不,我的第一个想法是代码已损坏,但是应用程序运行正确。另外,如果我测试是否使用 allocates[:site] 分配值,则测试通过。
有谁知道我需要更改什么才能使这些测试再次开始工作。
提前致谢
安迪
最佳答案
您需要在 it
语句之前调用 subject {controller }
。这实际上让我困惑了一段时间,所以我写了 my first ever blog post about it .
关于ruby-on-rails - allocate_to 不适用于 Ubuntu 上的 Rails 3 Shoulda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3747302/
我是一名优秀的程序员,十分优秀!