Permalink
Browse files

Add a pair of spec helpers

  • Loading branch information...
simonewebdesign committed Dec 31, 2012
1 parent 17f53eb commit f1c4ec53e602046e9f30a676620b54d2a270ded0
@@ -8,7 +8,7 @@
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
- it { should have_selector('title', text: 'Sign in') }
+ it { should have_title('Sign in') }
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
@@ -19,7 +19,7 @@
# end
before { valid_signin(user) }
- it { should have_selector('title', text: user.name) }
+ it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
@@ -28,7 +28,7 @@
describe "with invalid information" do
before { click_button "Sign in" }
- it { should have_selector('title', text: 'Sign in') }
+ it { should have_title('Sign in') }
it { should have_error_message('Invalid') }
describe "after visiting another page" do
@@ -6,7 +6,7 @@
shared_examples_for "all static pages" do
it { should have_selector('h1', text: heading) }
- it { should have_selector('title', text: full_title(page_title)) }
+ it { should have_title(full_title(page_title)) }
end
describe "Home page" do
@@ -8,7 +8,7 @@
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
- it { should have_selector('title', text: 'Sign up') }
+ it { should have_title('Sign up') }
end
@@ -20,7 +20,7 @@
it { should have_selector('h1', text: user.name) }
end
define "username should be in title" do
- it { should have_selector('title', text: user.name) }
+ it { should have_title(user.name) }
end
end
@@ -39,7 +39,7 @@
describe "after submission" do
before { click_button submit }
- it { should have_selector('title', text: 'Sign up') }
+ it { should have_title('Sign up') }
it { should have_content('error') }
end
@@ -61,10 +61,11 @@
before { click_button submit }
let(:user) { User.find_by_email('user@example.com') }
- it { should have_selector('title', text: user.name) }
- it { should have_selector('div.alert.alert-success', text: 'Welcome') }
+ it { should have_title(user.name) }
+ it { should have_success_message('Welcome') }
it { should have_link('Sign out') }
+
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
View
@@ -23,3 +23,15 @@ def valid_signin(user)
page.should have_selector('div.alert.alert-error', text: message)
end
end
+
+RSpec::Matchers.define :have_success_message do |message|
+ match do |page|
+ page.should have_selector('div.alert.alert-success', text: message)
+ end
+end
+
+RSpec::Matchers.define :have_title do |title|
+ match do |page|
+ page.should have_title(title)
+ end
+end

0 comments on commit f1c4ec5

Please sign in to comment.