Whitespace

This commit is contained in:
Bryan Helmkamp 2009-02-15 18:57:53 -05:00
parent 24eab77ecd
commit 7ba620f38b

View File

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