forked from yasslab/railsguides.jp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--require spec_helper | ||
--require turnip/rspec |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# language: ja | ||
|
||
フィーチャ: あるバージョンを読んでる最中、突然他のバージョンに移動することはないし、本の中のリンクはしなない | ||
シナリオ: トップページにアクセスしてログインする | ||
前提 "asset_pipeline" を表示する | ||
ならば 表示されている内部リンクは、すべて有効である | ||
|
||
シナリオ: トップページにアクセスしてログインする | ||
前提 "4_1_release_notes" を表示する | ||
ならば 表示されている内部リンクは、すべて有効である |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rack/file' | ||
require 'capybara/rspec' | ||
require 'turnip' | ||
require 'turnip/capybara' | ||
|
||
Dir.glob("spec/**/*steps.rb") { |f| load f, true } | ||
Dir.glob("spec/support/**/*.rb") { |f| load f, true } | ||
|
||
RSpec.configure do |config| | ||
config.color = true | ||
end | ||
|
||
Capybara.app = Rack::File.new(File.expand_path('../../guides/output', __FILE__)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
step '表示されている内部リンクは、すべて有効である' do | ||
_, internal_links = all('a').partition {|link| link[:href].start_with? 'http' } | ||
fragment_links = internal_links.select {|link| link[:href] =~ /#/ } | ||
|
||
# ["#active-record-enums"], ["/asset_pipeline.html#css%E3%81%A8erb"] | ||
same_pages, other_pages = fragment_links.partition {|link| link[:href] =~ /\A#/ } | ||
|
||
same_pages.each do |link| | ||
expect(link).to_not be_dead_fragment(page) | ||
end | ||
|
||
other_pages.each do |link| | ||
file, _ = link[:href].split("#", 2) | ||
original_page_path = page.current_path | ||
visit file | ||
expect(link).to_not be_dead_fragment(page, original_page_path) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
step ":file を表示する" do |file| | ||
# visit '/4_1_release_notes.html' | ||
visit "#{file}.html" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'uri' | ||
|
||
# cf: https://gist.github.com/hanachin/9968957 | ||
RSpec::Matchers.define :be_dead_fragment do |page, original_page_path=nil| | ||
define_method :id_from_link do |link| | ||
_, fragment = link[:href].split("#", 2) | ||
id = URI.unescape(fragment) | ||
end | ||
|
||
match do |link| | ||
begin | ||
!page.find_by_id(id_from_link(link)) | ||
rescue | ||
true | ||
end | ||
end | ||
|
||
failure_message_when_negated do |link| | ||
if original_page_path | ||
"Link(id: #{id_from_link(link)}, text: #{link.text}, original_page_path: #{original_page_path}) is dead fragment" | ||
else | ||
"Link(id: #{id_from_link(link)}, text: #{link.text}) is dead fragment" | ||
end | ||
end | ||
|
||
failure_message do |link| | ||
if original_page_path | ||
"Link(id: #{id_from_link(link)}, text: #{link.text}, original_page_path: #{original_page_path}) is not dead fragment" | ||
else | ||
"Link(id: #{id_from_link(link)}, text: #{link.text}) is not dead fragment" | ||
end | ||
end | ||
end |