From f814b79ac1a25775a510031956c57da53feb3ab2 Mon Sep 17 00:00:00 2001 From: Amos King Date: Mon, 5 Jan 2009 12:58:40 -0600 Subject: [PATCH 1/3] change assert_xpath and assert_no_xpath to be assert_have_xpath and assert _have_no_xpath to be closer to the rspec matcher. --- lib/webrat/core/matchers/have_xpath.rb | 4 ++-- spec/public/matchers_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/webrat/core/matchers/have_xpath.rb b/lib/webrat/core/matchers/have_xpath.rb index 532795eb..cc15a7a5 100644 --- a/lib/webrat/core/matchers/have_xpath.rb +++ b/lib/webrat/core/matchers/have_xpath.rb @@ -79,12 +79,12 @@ def have_xpath(expected, &block) end alias_method :match_xpath, :have_xpath - def assert_xpath(expected, &block) + def assert_have_xpath(expected, &block) hs = HaveXpath.new(expected, &block) raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body) end - def assert_no_xpath(expected, &block) + def assert_have_no_xpath(expected, &block) hs = HaveXpath.new(expected, &block) raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body) end diff --git a/spec/public/matchers_spec.rb b/spec/public/matchers_spec.rb index 26f8e03f..7a4649be 100644 --- a/spec/public/matchers_spec.rb +++ b/spec/public/matchers_spec.rb @@ -59,24 +59,24 @@ should_receive(:response_body).and_return @body require 'test/unit' end - describe "assert_xpath" do + describe "assert_have_xpath" do it "should pass when body contains the selection" do - assert_xpath("//div") + assert_have_xpath("//div") end it "should throw an exception when the body doesnt have matching xpath" do - lambda {assert_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError) end end - describe "assert_no_xpath" do + describe "assert_have_no_xpath" do it "should pass when the body doesn't contan the xpath" do - assert_no_xpath("//p") + assert_have_no_xpath("//p") end it "should throw an exception when the body does contain the xpath" do - lambda {assert_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError) end end end From ff00ae10ea45d895c843196009fed0a3c631c072 Mon Sep 17 00:00:00 2001 From: Amos King Date: Mon, 5 Jan 2009 12:59:56 -0600 Subject: [PATCH 2/3] add have to assert_selector and assert_no_selector for consistency. --- lib/webrat/core/matchers/have_selector.rb | 4 ++-- spec/public/matchers_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/webrat/core/matchers/have_selector.rb b/lib/webrat/core/matchers/have_selector.rb index 8052901f..b6278bd9 100644 --- a/lib/webrat/core/matchers/have_selector.rb +++ b/lib/webrat/core/matchers/have_selector.rb @@ -36,14 +36,14 @@ def have_selector(expected, &block) # Asserts that the body of the response contains # the supplied selector - def assert_selector(expected) + def assert_have_selector(expected) hs = HaveSelector.new(expected) raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body) end # Asserts that the body of the response # does not contain the supplied string or regepx - def assert_no_selector(expected) + def assert_have_no_selector(expected) hs = HaveSelector.new(expected) raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body) end diff --git a/spec/public/matchers_spec.rb b/spec/public/matchers_spec.rb index 7a4649be..58b173de 100644 --- a/spec/public/matchers_spec.rb +++ b/spec/public/matchers_spec.rb @@ -118,24 +118,24 @@ should_receive(:response_body).and_return @body require 'test/unit' end - describe "assert_selector" do + describe "assert_have_selector" do it "should pass when body contains the selection" do - assert_selector("div") + assert_have_selector("div") end it "should throw an exception when the body doesnt have matching selection" do - lambda {assert_selector("p")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_selector("p")}.should raise_error(Test::Unit::AssertionFailedError) end end - describe "assert_not_selector" do + describe "assert_have_not_selector" do it "should pass when the body doesn't contan the selection" do - assert_no_selector("p") + assert_have_no_selector("p") end it "should throw an exception when the body does contain the selection" do - lambda {assert_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError) end end end From 021f197abc9f3555987ee8bd232738ab0da687ca Mon Sep 17 00:00:00 2001 From: Amos King Date: Mon, 5 Jan 2009 13:03:08 -0600 Subject: [PATCH 3/3] change assert_tag and assert_no_tag to assert_have_tag and assert_no_tag so it won't conflict with rails and so that it will be more like the matchers. --- lib/webrat/core/matchers/have_tag.rb | 4 ++-- spec/public/matchers_spec.rb | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/webrat/core/matchers/have_tag.rb b/lib/webrat/core/matchers/have_tag.rb index 2e32913c..c39ffd91 100644 --- a/lib/webrat/core/matchers/have_tag.rb +++ b/lib/webrat/core/matchers/have_tag.rb @@ -55,14 +55,14 @@ def have_tag(name, attributes = {}, &block) # Asserts that the body of the response contains # the supplied tag with the associated selectors - def assert_tag(name, attributes = {}) + def assert_have_tag(name, attributes = {}) ht = HaveTag.new([name, attributes]) raise Test::Unit::AssertionFailedError.new(ht.failure_message) unless ht.matches?(response_body) end # Asserts that the body of the response # does not contain the supplied string or regepx - def assert_no_tag(name, attributes = {}) + def assert_have_no_tag(name, attributes = {}) ht = HaveTag.new([name, attributes]) raise Test::Unit::AssertionFailedError.new(ht.negative_failure_message) if ht.matches?(response_body) end diff --git a/spec/public/matchers_spec.rb b/spec/public/matchers_spec.rb index 58b173de..853d6886 100644 --- a/spec/public/matchers_spec.rb +++ b/spec/public/matchers_spec.rb @@ -192,40 +192,40 @@ should_receive(:response_body).and_return @body require 'test/unit' end - describe "assert_tag" do + describe "assert_have_tag" do it "should pass when body contains the tag" do - assert_tag("div") + assert_have_tag("div") end it "should pass when finding with additional selectors" do - assert_tag("div", :class => "inner") + assert_have_tag("div", :class => "inner") end it "should throw an exception when the body doesnt have matching tag" do - lambda {assert_tag("p")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_tag("p")}.should raise_error(Test::Unit::AssertionFailedError) end it "should throw an exception when the body doens't have a tag matching the additional selector" do - lambda {assert_tag("div", :class => "nope")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_tag("div", :class => "nope")}.should raise_error(Test::Unit::AssertionFailedError) end end - describe "assert_no_tag" do + describe "assert_have_no_tag" do it "should pass when the body doesn't contan the tag" do - assert_no_tag("p") + assert_have_no_tag("p") end it "should pass when the body doesn't contain the tag due to additional selectors missing" do - assert_no_tag("div", :class => "nope") + assert_have_no_tag("div", :class => "nope") end it "should throw an exception when the body does contain the tag" do - lambda {assert_no_tag("div")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_no_tag("div")}.should raise_error(Test::Unit::AssertionFailedError) end it "should throw an exception when the body contains the tag with additional selectors" do - lambda {assert_no_tag("div", :class => "inner")}.should raise_error(Test::Unit::AssertionFailedError) + lambda {assert_have_no_tag("div", :class => "inner")}.should raise_error(Test::Unit::AssertionFailedError) end end end