在我的認證規範,我有與軌道4
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "Signup page" do
before { visit new_user_registration_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_content('Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "First name", with: "Example"
fill_in "Last name", with: "Lastname"
fill_in "Username", with: "exampleguy"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar1234"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
#describe "after saving the user" do
#before { click_button submit }
#let(:user) { User.find_by(email: '[email protected]') }
#it { should have_title(user.first_name) }
#it { should have_selector('div.flash_success', text: 'Welcome') }
# end
end
it { should have_content('Sign up') }
end
describe "Signin page" do
before { visit new_user_session_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_content('Sign in') }
it { should have_selector('div.flash_alert', text: "Invalid") }
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should_not have_selector('a', text: 'Sign up')}
it { should_not have_selector('a', text: 'Sign in')}
it { should have_selector('a', text: 'Profile') }
it { should have_selector('a', text: 'Sign Out') }
it { should have_selector('div.flash_notice', text: "Signed in successfully.") }
end
it { should have_content('Sign in') }
end
end
而且在factories.rb試驗設計Rspec的跡象
FactoryGirl.define do
factory :user do
first_name "Example"
last_name "User"
username "exampleuser"
email "[email protected]"
password "foobar1234"
end
end
每個測試從登錄-with有效信息組工作分開的測試。我不知道爲什麼,它在瀏覽器中正常工作。有沒有人遇到過這樣的問題?
你可以添加失敗的行嗎? – tyler
是那些在登錄頁面 - >有效的信息,例如它{should_not have_selector('a',text:'註冊')}以及該測試組中的其餘部分。 – Skyalchemist