gpt4 book ai didi

ruby-on-rails - allocate_to 不适用于 Ubuntu 上的 Rails 3 Shoulda

转载 作者:行者123 更新时间:2023-12-02 02:40:37 24 4
gpt4 key购买 nike

我正在将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com