Created
November 25, 2013 03:57
-
-
Save kidach1/7636139 to your computer and use it in GitHub Desktop.
[Rails] RSpecのリファクタリング ref: http://qiita.com/kidachi_/items/ec184deb106e4e5c90c3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
# ページごとの完全なタイトルを返却 | |
def full_title(page_title) | |
base_title = "Ruby on Rails Tutorial Sample App" | |
if page_title.empty? | |
base_title | |
else | |
"#{base_title} | #{page_title}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ApplicationHelper do | |
describe "full_title" do | |
it "should include the page title" do | |
expect(full_title("foo")).to match(/foo/) | |
end | |
it "should include the base title" do | |
expect(full_title("foo")).to match(/^Ruby on Rails Tutorial Sample App/) | |
end | |
it "should not include a bar for the home page" do | |
expect(full_title("")).not_to match(/\|/) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Static pages" do | |
describe "Home page" do | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should have the h1 'Sample App'" do | |
visit root_path | |
page.should have_selector('h1', text: 'Sample App') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let(:variable) { 'hoge' } | |
# 値’hoge’を持つ変数variableが使えるようになる。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Static pages" do | |
subject { page } | |
shared_examples_for "fuga" do | |
it { should have_content(variable1) } | |
it { should have_title(full_title(variable2)) } | |
end | |
~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Home page" do | |
let(:variable1) { 'Sample App' } | |
let(:variable2) { '' } | |
it_should_behave_like "fuga" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "Static pages" do | |
subject { page } | |
shared_examples_for "all static pages" do | |
it { should have_content(heading) } | |
it { should have_title(full_title(page_title)) } | |
end | |
describe "Home page" do | |
before { visit root_path } | |
let(:heading) { 'Sample App' } | |
let(:page_title) { '' } | |
it_should_behave_like "all static pages" | |
it { should_not have_title('| Home') } | |
end | |
describe "About page" do | |
before { visit about_path } | |
let(:heading) { 'About' } | |
let(:page_title) { 'About' } | |
it_should_behave_like "all static pages" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment