diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index e6a8ee4..2779386 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -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 diff --git a/spec/support/matchers/have_text.rb b/spec/support/matchers/have_text.rb new file mode 100644 index 0000000..c1efddf --- /dev/null +++ b/spec/support/matchers/have_text.rb @@ -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