Permalink
Browse files

wrapped assertions

  • Loading branch information...
dchelimsky committed Oct 10, 2009
1 parent df92ea6 commit 76eecef955a28c4d116a9652e417a5f2b32a4c33
View
Binary file not shown.
@@ -1,2 +1,5 @@
module AccountsHelper
+ def link_to_account(account)
+ %Q{<a href="/accounts/#{account.id}">#{account.name}'s account</a>}
+ end
end
@@ -1,11 +1,54 @@
require 'spec_helper'
-describe AccountsHelper do
+module WrappedAssertions
+ attr_reader :assertion_error
+
+ def self.extension_modules
+ @extension_modules ||= [Test::Unit::Assertions]
+ end
+
+ def self.add_assertions(mod)
+ extension_modules << mod
+ end
+
+ def wrap_assertion
+ WrappedAssertions.extension_modules.map {|mod| extend mod}
+ begin
+ yield
+ true
+ rescue Exception => e
+ @assertion_error = e
+ false
+ end
+ end
+end
- #Delete this example and add some real ones or delete this file
- it "is included in the helper object" do
- included_modules = (class << helper; self; end).send :included_modules
- included_modules.should include(AccountsHelper)
+WrappedAssertions.add_assertions ActionController::TestCase::Assertions
+
+Spec::Matchers.define :match_dom do |expected|
+ extend WrappedAssertions
+ match do |actual|
+ wrap_assertion do
+ assert_dom_equal expected, actual
+ end
end
+end
+describe AccountsHelper do
+ describe "#link_to_account" do
+ it "renders a link to the account" do
+ account = mock_model(Account, :id => "37", :name => "David")
+ assert_dom_equal %Q{<a href="/accounts/37">David's account</a>}, helper.link_to_account(account)
+ end
+
+ it "renders a link to the account" do
+ account = mock_model(Account, :id => "38", :name => "David")
+ helper.link_to_account(account).should match_dom(%Q{<a href="/accounts/37">David's account</a>})
+ end
+
+ it "does not render a link to another account" do
+ account = mock_model(Account, :id => "37", :name => "David")
+ helper.link_to_account(account).should_not match_dom(%Q{<a href="/accounts/38">David's account</a>})
+ end
+ end
end

0 comments on commit 76eecef

Please sign in to comment.