我正在用RSpec,FactoryGirls測試控制器。
這是我factories.rb如何創建用戶的文章
FactoryGirl.define do
factory :user do |user|
user.sequence(:name) { Faker::Internet.user_name }
user.email Faker::Internet.email
user.password "password"
user.password_confirmation "password"
end
factory :article do
user
title Faker::Lorem.sentence(5)
content Faker::Lorem.paragraph(20)
end
end
我怎麼能在這裏創建用戶
的文章,這是articles_controller_spec
describe ArticlesController do
let(:user) do
user = FactoryGirl.create(:user)
user.confirm!
user
end
describe "GET #index" do
it "populates an array of articles of the user" do
#how can i create an article of the user here
sign_in user
get :index
assigns(:articles).should eq([article])
end
it "renders the :index view" do
get :index
response.should render_template :index
end
end
end
你想測試'ArticlesController'的'create'動作? – Naveed 2013-04-24 14:08:48
不,索引行動ArticlesController – 2013-04-24 14:16:20
看到我更新的答案 – Naveed 2013-04-24 14:21:50