Created
November 25, 2009 05:28
-
-
Save thumblemonks/242505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/test_helper.rb b/test/test_helper.rb | |
index 8ca9c51..8e13d5d 100644 | |
--- a/test/test_helper.rb | |
+++ b/test/test_helper.rb | |
@@ -10,23 +10,28 @@ require 'toto' | |
module Riot | |
class Assertion | |
assertion(:includes) do |actual, expected| | |
- actual.include?(expected) || fail("expected #{actual} to include #{expected}") | |
+ actual.include?(expected) ? pass : fail("expected #{actual} to include #{expected}") | |
end | |
assertion(:includes_html) do |actual, expected| | |
doc = Hpricot.parse(actual) | |
expected = expected.to_a.flatten | |
- !(doc/expected.first).empty? || fail("expected #{actual} to contain a <#{expected.first}>") | |
- (doc/expected.first).inner_html.match(expected.last) || fail("expected <#{expected.first}> to contain #{expected.last}") | |
+ if (doc/expected.first).empty? | |
+ fail("expected #{actual} to contain a <#{expected.first}>") | |
+ elsif !(doc/expected.first).inner_html.match(expected.last) | |
+ fail("expected <#{expected.first}> to contain #{expected.last}") | |
+ else | |
+ pass | |
+ end | |
end | |
assertion(:includes_elements) do |actual, selector, count| | |
doc = Hpricot.parse(actual) | |
- (doc/selector).size == count || fail("expected #{actual} to contain #{count} #{selector}(s)") | |
+ (doc/selector).size == count ? pass : fail("expected #{actual} to contain #{count} #{selector}(s)") | |
end | |
assertion(:within) do |actual, expected| | |
- expected.include?(actual) || fail("expected #{actual} to be within #{expected}") | |
+ expected.include?(actual) ? pass : fail("expected #{actual} to be within #{expected}") | |
end | |
end | |
end | |
diff --git a/test/toto_test.rb b/test/toto_test.rb | |
index 1be095a..65712f0 100644 | |
--- a/test/toto_test.rb | |
+++ b/test/toto_test.rb | |
@@ -15,11 +15,11 @@ context Toto do | |
context "GET /" do | |
setup { @toto.get('/') } | |
+ should("include a couple of article") { topic.body }.includes_elements("#articles li", 3) | |
+ should("include an archive") { topic.body }.includes_elements("#archives li", 2) | |
asserts("returns a 200") { topic.status }.equals 200 | |
asserts("body is not empty") { not topic.body.empty? } | |
asserts("content type is set properly") { topic.content_type }.equals "text/html" | |
- should("include a couple of article") { topic.body }.includes_elements("#articles li", 3) | |
- should("include an archive") { topic.body }.includes_elements("#archives li", 2) | |
context "with no articles" do | |
setup { Rack::MockRequest.new(Toto::Server.new(@config.merge(:ext => 'oxo'))).get('/') } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment