Skip to content

Instantly share code, notes, and snippets.

@francois
Created May 8, 2009 13:14
Show Gist options
  • Select an option

  • Save francois/108771 to your computer and use it in GitHub Desktop.

Select an option

Save francois/108771 to your computer and use it in GitHub Desktop.
1) Failure:
test: Pets::Dog should flunk. (Pets::DogTest)
[./test/unit/dog_test.rb:10
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:145:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:145:in `load'
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb:5
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb:5:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader.rb:5]:
Flunked.
diff --git a/lib/shoulda/context.rb b/lib/shoulda/context.rb
index 948f18c..510d673 100644
--- a/lib/shoulda/context.rb
+++ b/lib/shoulda/context.rb
@@ -58,6 +58,7 @@ module Shoulda
# end
def should(name, options = {}, &blk)
+ options[:backtrace] = caller unless options.has_key?(:backtrace)
if Shoulda.current_context
block_given? ? Shoulda.current_context.should(name, options, &blk) : Should.current_context.should_eventually(name)
else
@@ -101,6 +102,7 @@ module Shoulda
# Just like should, but never runs, and instead prints an 'X' in the Test::Unit output.
def should_eventually(name, options = {}, &blk)
+ options[:backtrace] = caller unless options.has_key?(:backtrace)
context_name = self.name.gsub(/Test/, "")
context = Shoulda::Context.new(context_name, self) do
should_eventually(name, &blk)
@@ -307,7 +309,7 @@ module Shoulda
def should(name, options = {}, &blk)
if block_given?
- self.shoulds << { :name => name, :before => options[:before], :block => blk }
+ self.shoulds << { :name => name, :before => options[:before], :backtrace => options[:backtrace], :block => blk }
else
self.should_eventuallys << { :name => name }
end
@@ -349,6 +351,10 @@ module Shoulda
should[:before].bind(self).call if should[:before]
context.run_current_setup_blocks(self)
should[:block].bind(self).call
+ rescue Test::Unit::AssertionFailedError => e
+ p e.instance_variables
+ e.set_backtrace(should[:backtrace]) if should.has_key?(:backtrace)
+ raise
ensure
context.run_all_teardown_blocks(self)
end
diff --git a/test/unit/dog_test.rb b/test/unit/dog_test.rb
index 03ff41f..113ea28 100644
--- a/test/unit/dog_test.rb
+++ b/test/unit/dog_test.rb
@@ -6,4 +6,8 @@ class Pets::DogTest < ActiveSupport::TestCase
should_have_many :treats
should_have_and_belong_to_many :fleas
should_validate_presence_of :owner_id, :treats, :fleas
+
+ should "flunk" do
+ flunk
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment