mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Make integration spec failures more descriptive
This commit is contained in:
parent
970f3a3b67
commit
21418f1890
2 changed files with 50 additions and 5 deletions
|
@ -1,22 +1,23 @@
|
|||
require 'spec_helper'
|
||||
require 'support/dummy_app'
|
||||
require 'support/matchers/have_text'
|
||||
|
||||
shared_examples_for "a decorator in a view" do
|
||||
it "works" do
|
||||
# it runs in the correct environment
|
||||
page.should have_css "#environment", text: environment
|
||||
page.should have_text(environment).in("#environment")
|
||||
|
||||
# it can use path helpers with a model
|
||||
page.should have_css "#path_with_model", text: "/en/posts/1"
|
||||
page.should have_text("/en/posts/1").in("#path_with_model")
|
||||
|
||||
# it can use path helpers with an id
|
||||
page.should have_css "#path_with_id", text: "/en/posts/1"
|
||||
page.should have_text("/en/posts/1").in("#path_with_id")
|
||||
|
||||
# it can use url helpers with a model
|
||||
page.should have_css "#url_with_model", text: "http://www.example.com/en/posts/1"
|
||||
page.should have_text("http://www.example.com/en/posts/1").in("#url_with_model")
|
||||
|
||||
# it can use url helpers with an id
|
||||
page.should have_css "#url_with_id", text: "http://www.example.com/en/posts/1"
|
||||
page.should have_text("http://www.example.com/en/posts/1").in("#url_with_id")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
44
spec/support/matchers/have_text.rb
Normal file
44
spec/support/matchers/have_text.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module HaveTextMatcher
|
||||
def have_text(text)
|
||||
HaveText.new(text)
|
||||
end
|
||||
|
||||
class HaveText
|
||||
def initialize(text)
|
||||
@text = text
|
||||
end
|
||||
|
||||
def in(css)
|
||||
@css = css
|
||||
self
|
||||
end
|
||||
|
||||
def matches?(subject)
|
||||
@subject = subject
|
||||
|
||||
@subject.has_css?(@css || "*", text: @text)
|
||||
end
|
||||
|
||||
def failure_message_for_should
|
||||
"expected to find #{@text.inspect} #{within}"
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
"expected not to find #{@text.inspect} #{within}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def within
|
||||
"#{inside} within\n#{@subject.html}"
|
||||
end
|
||||
|
||||
def inside
|
||||
@css ? "inside #{@css.inspect}" : "anywhere"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include HaveTextMatcher
|
||||
end
|
Loading…
Add table
Reference in a new issue