Whitespace

This commit is contained in:
Bryan Helmkamp 2009-02-15 18:57:53 -05:00
parent 24eab77ecd
commit 7ba620f38b
1 changed files with 83 additions and 45 deletions

View File

@ -40,34 +40,43 @@ describe Webrat::Matchers do
end
it "should be able to use #have_xpath in the block" do
@body.should have_xpath("//div[@id='main']") { |node| node.should have_xpath("./div[@class='inner']") }
@body.should have_xpath("//div[@id='main']") do |node|
node.should have_xpath("./div[@class='inner']")
end
end
it "should convert absolute paths to relative in the block" do
@body.should have_xpath("//div[@id='main']") { |node| node.should have_xpath("//div[@class='inner']") }
@body.should have_xpath("//div[@id='main']") do |node|
node.should have_xpath("//div[@class='inner']")
end
end
it "should not match any parent tags in the block" do
lambda {
@body.should have_xpath("//div[@class='inner']") { |node| node.should have_xpath("//div[@id='main']") }
@body.should have_xpath("//div[@class='inner']") do |node|
node.should have_xpath("//div[@id='main']")
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
describe 'asserts for xpath' do
include Test::Unit::Assertions
before(:each) do
should_receive(:response_body).and_return @body
require 'test/unit'
end
describe "assert_have_xpath" do
it "should pass when body contains the selection" do
assert_have_xpath("//div")
end
it "should throw an exception when the body doesnt have matching xpath" do
lambda {assert_have_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_have_xpath("//p")
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
describe "assert_have_no_xpath" do
@ -76,11 +85,12 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body does contain the xpath" do
lambda {assert_have_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_have_no_xpath("//div")
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
end
end
describe "#have_selector" do
@ -108,30 +118,37 @@ describe Webrat::Matchers do
end
it "should be able to use #have_selector in the block" do
@body.should have_selector("#main") { |node| node.should have_selector(".inner") }
@body.should have_selector("#main") do |node|
node.should have_selector(".inner")
end
end
it "should not match any parent tags in the block" do
lambda {
@body.should have_selector(".inner") { |node| node.should have_selector("#main") }
@body.should have_selector(".inner") do |node|
node.should have_selector("#main")
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
describe "asserts for selector," do
include Test::Unit::Assertions
before(:each) do
should_receive(:response_body).and_return @body
require 'test/unit'
end
describe "assert_have_selector" do
it "should pass when body contains the selection" do
assert_have_selector("div")
end
it "should throw an exception when the body doesnt have matching selection" do
lambda {assert_have_selector("p")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_have_selector("p")
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
describe "assert_have_not_selector" do
@ -140,15 +157,15 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body does contain the selection" do
lambda {assert_have_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_have_no_selector("div")
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
end
end
describe "#have_tag" do
it "should be able to match a tag" do
@body.should have_tag("div")
end
@ -180,12 +197,16 @@ describe Webrat::Matchers do
end
it "should be able to use #have_tag in the block" do
@body.should have_tag("div", :id => "main") { |node| node.should have_tag("div", :class => "inner") }
@body.should have_tag("div", :id => "main") do |node|
node.should have_tag("div", :class => "inner")
end
end
it "should not match any parent tags in the block" do
lambda {
@body.should have_tag("div", :class => "inner") { |node| node.should have_tag("div", :id => "main") }
@body.should have_tag("div", :class => "inner") do |node|
node.should have_tag("div", :id => "main")
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
@ -212,12 +233,16 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body doesnt have matching tag" do
lambda {assert_have_tag("p")}.should raise_error(Test::Unit::AssertionFailedError)
it "should throw an exception when the body doesn't have matching tag" do
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_have_tag("div", :class => "nope")}.should raise_error(Test::Unit::AssertionFailedError)
it "should throw an exception when the body doesn't have a tag matching the attributes" do
lambda {
assert_have_tag("div", :class => "nope")
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
@ -231,11 +256,15 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body does contain the tag" do
lambda {assert_have_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_have_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
@ -265,10 +294,12 @@ describe Webrat::Matchers do
describe "asserts for contains," do
include Test::Unit::Assertions
before(:each) do
should_receive(:response_body).and_return @body
require 'test/unit'
end
describe "assert_contain" do
it "should pass when containing the text" do
assert_contain("hello, world")
@ -279,11 +310,15 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body doesnt contain the text" do
lambda {assert_contain("monkeys")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_contain("monkeys")
}.should raise_error(Test::Unit::AssertionFailedError)
end
it "should throw an exception when the body doesnt contain the regexp" do
lambda {assert_contain(/monkeys/)}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_contain(/monkeys/)
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
@ -297,17 +332,20 @@ describe Webrat::Matchers do
end
it "should throw an exception when the body does contain the text" do
lambda {assert_not_contain("hello, world")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_not_contain("hello, world")
}.should raise_error(Test::Unit::AssertionFailedError)
end
it "should throw an exception when the body does contain the regexp" do
lambda {assert_not_contain(/hello, world/)}.should raise_error(Test::Unit::AssertionFailedError)
lambda {
assert_not_contain(/hello, world/)
}.should raise_error(Test::Unit::AssertionFailedError)
end
end
end
describe "#failure_message" do
it "should include the content string" do
hc = Webrat::Matchers::HasContent.new("hello, world!")
hc.matches?(@body)