Skip to content

Commit

Permalink
Eliminate test example duplication with shared examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dskecse committed Feb 26, 2014
1 parent 6b93e1d commit d3f4460
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 12 additions & 8 deletions spec/requests/static_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@

describe 'Home page' do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }

it { should have_content('Sample App') }
it { should have_title(full_title('')) }
it_should_behave_like 'all static pages'
it { should_not have_title('| Home') }
end

describe 'Help page' do
before { visit help_path }
let(:heading) { 'Help' }
let(:page_title) { 'Help' }

it { should have_content('Help') }
it { should have_title(full_title('Help')) }
it_should_behave_like 'all static pages'
end

describe 'About page' do
before { visit about_path }
let(:heading) { 'About Us' }
let(:page_title) { 'About' }

it { should have_content('About Us') }
it { should have_title(full_title('About')) }
it_should_behave_like 'all static pages'
end

describe 'Contact page' do
before { visit contact_path }
let(:heading) { 'Contact' }
let(:page_title) { 'Contact' }

it { should have_selector('h1', text: 'Contact') }
it { should have_title(full_title('Contact')) }
it_should_behave_like 'all static pages'
end
end
4 changes: 4 additions & 0 deletions spec/support/shared/static_pages_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shared_examples_for 'all static pages' do
it { should have_selector('h1', text: heading) }
it { should have_title(full_title(page_title)) }
end

0 comments on commit d3f4460

Please sign in to comment.