Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a pair of spec helpers

  • Loading branch information...
commit f1c4ec53e602046e9f30a676620b54d2a270ded0 1 parent 17f53eb
Simone Vittori authored December 31, 2012
6  spec/requests/authentication_pages_spec.rb
@@ -8,7 +8,7 @@
8 8
     before { visit signin_path }
9 9
 
10 10
     it { should have_selector('h1',    text: 'Sign in') }
11  
-    it { should have_selector('title', text: 'Sign in') }
  11
+    it { should have_title('Sign in') }
12 12
 
13 13
     describe "with valid information" do
14 14
       let(:user) { FactoryGirl.create(:user) }
@@ -19,7 +19,7 @@
19 19
     # end
20 20
       before { valid_signin(user) }
21 21
 
22  
-      it { should have_selector('title', text: user.name) }
  22
+      it { should have_title(user.name) }
23 23
       it { should have_link('Profile', href: user_path(user)) }
24 24
       it { should have_link('Sign out', href: signout_path) }
25 25
       it { should_not have_link('Sign in', href: signin_path) }
@@ -28,7 +28,7 @@
28 28
     describe "with invalid information" do
29 29
       before { click_button "Sign in" }
30 30
 
31  
-      it { should have_selector('title', text: 'Sign in') }
  31
+      it { should have_title('Sign in') }
32 32
       it { should have_error_message('Invalid') }
33 33
 
34 34
       describe "after visiting another page" do
2  spec/requests/static_pages_spec.rb
@@ -6,7 +6,7 @@
6 6
 
7 7
   shared_examples_for "all static pages" do
8 8
     it { should have_selector('h1',    text: heading) }
9  
-    it { should have_selector('title', text: full_title(page_title)) }
  9
+    it { should have_title(full_title(page_title)) }
10 10
   end
11 11
 
12 12
   describe "Home page" do
11  spec/requests/user_pages_spec.rb
@@ -8,7 +8,7 @@
8 8
     before { visit signup_path }
9 9
 
10 10
     it { should have_selector('h1',    text: 'Sign up') }
11  
-    it { should have_selector('title', text: 'Sign up') }
  11
+    it { should have_title('Sign up') }
12 12
 
13 13
   end
14 14
 
@@ -20,7 +20,7 @@
20 20
       it { should have_selector('h1',    text: user.name) }
21 21
     end
22 22
     define "username should be in title" do      
23  
-      it { should have_selector('title', text: user.name) }
  23
+      it { should have_title(user.name) }
24 24
     end
25 25
   end
26 26
 
@@ -39,7 +39,7 @@
39 39
       describe "after submission" do
40 40
         before { click_button submit }
41 41
 
42  
-        it { should have_selector('title', text: 'Sign up') }
  42
+        it { should have_title('Sign up') }
43 43
         it { should have_content('error') }
44 44
       end
45 45
       
@@ -61,10 +61,11 @@
61 61
         before { click_button submit }
62 62
         let(:user) { User.find_by_email('user@example.com') }
63 63
 
64  
-        it { should have_selector('title', text: user.name) }
65  
-        it { should have_selector('div.alert.alert-success', text: 'Welcome') }
  64
+        it { should have_title(user.name) }
  65
+        it { should have_success_message('Welcome') }
66 66
         it { should have_link('Sign out') }
67 67
 
  68
+
68 69
         describe "followed by signout" do
69 70
           before { click_link "Sign out" }
70 71
           it { should have_link('Sign in') }
12  spec/support/utilities.rb
@@ -23,3 +23,15 @@ def valid_signin(user)
23 23
     page.should have_selector('div.alert.alert-error', text: message)
24 24
   end
25 25
 end
  26
+
  27
+RSpec::Matchers.define :have_success_message do |message|
  28
+  match do |page|
  29
+    page.should have_selector('div.alert.alert-success', text: message)
  30
+  end
  31
+end
  32
+
  33
+RSpec::Matchers.define :have_title do |title|
  34
+  match do |page|
  35
+    page.should have_title(title)
  36
+  end
  37
+end

0 notes on commit f1c4ec5

Please sign in to comment.
Something went wrong with that request. Please try again.