我是rails的新人,我正在使用capybara rspec和工厂女孩来测试我的设计宝石用户。
此处的规范代码:
require 'rails_helper'
RSpec.describe User, type: :request do
it "displays the user's email after successful login" do
user = FactoryGirl.create(:user, email: 'test@test.com', password: 'password')
visit root_url
fill_in 'Email', with: 'test@test.com'
fill_in 'Password', with: 'password'
click_button 'Log in'
expect page.has_content?('jdoe')
end
end
问题在于
期待page.has_content?(' jdoe') 无论我把它放在什么地方而且“jdoe'测试完美无误。
这里的工厂:
FactoryGirl.define do
factory :user do
email 'test@test.com'
password 'password'
password_confirmation 'password'
end
end
也许我错过了什么或者走错路。我该怎么在这里测试?
答案 0 :(得分:1)
allocator
这里有一些事情:
# spec/features/sessions_spec.rb
require 'rails_helper'
RSpec.feature "Sessions" do
scenario "displays the user's email after successful login" do
user = FactoryGirl.create(:user)
visit root_url
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Log in'
expect(page).to have_content("Signed in successfully")
# will give a false postitive if form is rerended?
expect(page).to have_content(user.email)
end
end
代替expect(page).to
。 expect page.should
设置主题并使用RSpec匹配器,如果不匹配,将在错误消息中显示页面文本。