这是我第一次使用RSpec与Capybara一起编写测试。这是我到目前为止所拥有的:
require 'capybara/rspec'
describe "the signin process" do
before :each do
User.make(:email => 'test@test.com', :password => 'thisisatest')
end
it 'signs me in' do
visit 'sessions/new'
within("session") do
fill_in 'user email', :with => 'test@test.com'
fill_in 'password', :with => 'thisisatest'
end
click_link 'login'
expect(page).to have_content 'Thank You'
end
end
以下是我运行测试时收到的消息:
the signin process
signs me in (FAILED - 1)
Failures:
1) the signin process signs me in
Failure/Error: User.make(:email => 'yedidyaweiner@gmail.com', :password => 'Shabbos!78')
NameError:
uninitialized constant User
# ./spec/features/sign_in_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.0006 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/sign_in_spec.rb:8 # the signin process signs me in
我如何解决这个问题,以便测试通过?关于如何更好地编写测试的任何建议?
答案 0 :(得分:0)
require 'spec_helper'
describe "The signin process" do
let!(:user) { User.create email: 'test@test.com', password: 'secret' }
it 'signs me in' do
visit 'sessions/new'
within("session") do
fill_in 'user email', with: user.email
fill_in 'password', with: user.password
end
click_link 'login'
expect(page).to have_content 'Thank You'
end
end