[英]Using assigns() in rspec view specs
I'm trying to model one of my view specs after the examples given here . 我正在尝试根据此处给出的示例对我的视图规范之一进行建模。
From my Gemfile: gem 'rspec-rails', '~> 3.0'
从我的Gemfile中:gem'rspec
gem 'rspec-rails', '~> 3.0'
# /app/spec/views/teams/index.html.haml_spec.rb
RSpec.describe "teams/index", type: :view do
before (:each) do
assigns(:teams, [
FactoryGirl.create(:team, name: "Team 1"),
FactoryGirl.create(:team, name: "Team 2")
])
end
it "renders a list of teams" do
render
expect(rendered).to match /Team 1/
expect(rendered).to match /Team 2/
end
end
This spec fails with: 该规范失败,原因是:
1) teams/index renders a list of teams
Failure/Error: assigns(:teams, [
ArgumentError:
wrong number of arguments (2 for 0..1)
I don't understand the failure... I'm doing exactly what the docs tell me to do. 我不明白失败的原因……我在做文档告诉我的事情。 What am I missing?
我想念什么?
You should use assign instead assigns : 您应该使用assign代替assigns :
before (:each) do
assign(:teams, [
FactoryGirl.create(:team, name: "Team 1"),
FactoryGirl.create(:team, name: "Team 2")
])
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.