diff --git a/lib/wrong/adapters/minitest.rb b/lib/wrong/adapters/minitest.rb index 9fae306..47c3c9a 100644 --- a/lib/wrong/adapters/minitest.rb +++ b/lib/wrong/adapters/minitest.rb @@ -13,5 +13,5 @@ def aver(valence, explanation = nil, depth = 0) self._assertions += 1 # increment minitest's assert count super(valence, explanation, depth + 1) # apparently this passes along the default block end - + end diff --git a/lib/wrong/adapters/rspec.rb b/lib/wrong/adapters/rspec.rb index 1be3869..2e87e47 100644 --- a/lib/wrong/adapters/rspec.rb +++ b/lib/wrong/adapters/rspec.rb @@ -19,78 +19,77 @@ module RSpec::Rails::TestUnitAssertionAdapter end end - # This would work if we didn't need to define failure_class - # todo: figure out how to get RSpec's config object to class_eval or whatever - # Rspec.configure do |config| - # config.include Wrong - # def failure_class - # RSpec::Expectations::ExpectationNotMetError - # end - # end + # This would work if we didn't need to define failure_class + # todo: figure out how to get RSpec's config object to class_eval or whatever + # Rspec.configure do |config| + # config.include Wrong + # def failure_class + # RSpec::Expectations::ExpectationNotMetError + # end + # end - module RSpec - module Core - class ExampleGroup - include Wrong + module RSpec + module Core + class ExampleGroup + include Wrong - def failure_class - RSpec::Expectations::ExpectationNotMetError - end - end - end - end + def failure_class + RSpec::Expectations::ExpectationNotMetError + end + end + end + end - # Disallow alias_assert :expect - module Wrong - class Config - alias :alias_assert_or_deny_original :alias_assert_or_deny - def alias_assert_or_deny(valence, extra_name, options = {}) - if extra_name.to_sym == :expect - if options[:override] - RSpec::Matchers.class_eval do - remove_method(:expect) - end - else - raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.") - end - end - alias_assert_or_deny_original(valence, extra_name, options) - end - end - end + # Disallow alias_assert :expect + module Wrong + class Config + alias :alias_assert_or_deny_original :alias_assert_or_deny + def alias_assert_or_deny(valence, extra_name, options = {}) + if extra_name.to_sym == :expect + if options[:override] + RSpec::Matchers.class_eval do + remove_method(:expect) + end + else + raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.") + end + end + alias_assert_or_deny_original(valence, extra_name, options) + end + end + end # tweak terminal width so exceptions wrap properly inside RSpec output Wrong::Terminal.width -= 7 elsif Object.const_defined? :Spec # RSpec 1 - Spec::Runner.configure do |config| - include Wrong + Spec::Runner.configure do |config| + include Wrong - def failure_class - Spec::Expectations::ExpectationNotMetError - end - end - - # Disallow alias_assert :expect - module Wrong - class Config - alias :alias_assert_or_deny_original :alias_assert_or_deny - def alias_assert_or_deny(valence, extra_name, options = {}) - if extra_name.to_sym == :expect - if options[:override] - Spec::Example::ExampleMethods.class_eval do - remove_method(:expect) - end - else - raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.") - end - end - alias_assert_or_deny_original(valence, extra_name, options) - end - end - end + def failure_class + Spec::Expectations::ExpectationNotMetError + end + end + # Disallow alias_assert :expect + module Wrong + class Config + alias :alias_assert_or_deny_original :alias_assert_or_deny + def alias_assert_or_deny(valence, extra_name, options = {}) + if extra_name.to_sym == :expect + if options[:override] + Spec::Example::ExampleMethods.class_eval do + remove_method(:expect) + end + else + raise ConfigError.new("RSpec already has a method named #{extra_name}. Use alias_#{valence} :#{extra_name}, :override => true if you really want to do this.") + end + end + alias_assert_or_deny_original(valence, extra_name, options) + end + end + end else raise "Wrong's RSpec adapter can't find RSpec. Please require 'spec' or 'rspec' before requiring 'wrong/adapters/rspec'." diff --git a/lib/wrong/config.rb b/lib/wrong/config.rb index 9ac0058..666df77 100644 --- a/lib/wrong/config.rb +++ b/lib/wrong/config.rb @@ -1,4 +1,3 @@ - module Wrong def self.load_config diff --git a/lib/wrong/eventually.rb b/lib/wrong/eventually.rb index 6054848..15a5647 100644 --- a/lib/wrong/eventually.rb +++ b/lib/wrong/eventually.rb @@ -1,14 +1,14 @@ module Wrong module Eventually NO_BLOCK_PASSED = "you must pass a block to the eventually method" - + def eventually options = {}, &block raise NO_BLOCK_PASSED if block.nil? timeout = options[:timeout] || 5 delay = options[:delay] || 0.25 last_error = nil success = nil - begin_time = Time.now + begin_time = Time.now while (Time.now - begin_time) < timeout begin aver(:assert, &block) diff --git a/lib/wrong/message/array_diff.rb b/lib/wrong/message/array_diff.rb index bf32704..dc3d187 100644 --- a/lib/wrong/message/array_diff.rb +++ b/lib/wrong/message/array_diff.rb @@ -24,7 +24,6 @@ def describe message << right_str + "\n" message << diff_str + "\n" message - end def compute_and_format(left, right) diff --git a/lib/wrong/message/test_context.rb b/lib/wrong/message/test_context.rb index 7ddd087..b7edb3f 100644 --- a/lib/wrong/message/test_context.rb +++ b/lib/wrong/message/test_context.rb @@ -4,11 +4,11 @@ module Assert # def failure_message(method_sym, block, predicate) upper_portion = super - + first_test_line = caller.find{|line|line =~ /(_test.rb|_spec.rb)/} raise "Can't find test or spec in call chain: #{caller.join('|')}" if first_test_line.nil? file, failure_line_number = first_test_line.split(":",2) - + lines = File.readlines(file) line_number = failure_line_number.to_i - 1 to_show = [] @@ -17,12 +17,12 @@ def failure_message(method_sym, block, predicate) to_show.unshift(line) line_number -= 1 end while !(line =~ /^\s+(test|it)[ ]+/ || line =~ /^\s+def test_\w+/) - - to_show[to_show.length-1] = to_show[to_show.length-1].chomp + + + to_show[to_show.length-1] = to_show[to_show.length-1].chomp + " ASSERTION FAILURE #{file}:#{failure_line_number.to_i}\n" - + upper_portion + "\n\n" + to_show.join end - + end end diff --git a/test/capturing_test.rb b/test/capturing_test.rb index ce7078a..e58cff1 100644 --- a/test/capturing_test.rb +++ b/test/capturing_test.rb @@ -29,7 +29,7 @@ assert { out == "hi\n"} assert { err == "bye\n"} end - + it "returns an empty string if nothing was emitted" do out, err = capturing(:stdout, :stderr) do end @@ -62,5 +62,4 @@ assert { e.message =~ /^stdout was reassigned/ } end - end diff --git a/test/message/test_context_test.rb b/test/message/test_context_test.rb index ad8ab18..d6ead85 100644 --- a/test/message/test_context_test.rb +++ b/test/message/test_context_test.rb @@ -5,7 +5,7 @@ xdescribe "showing the lines just above where the failure occurs, so you have some context" do include Wrong::Assert - + it "you can see test method all the way back to the start of the test, plus an indication of where the failure was" do a = 1 b = 2 @@ -26,12 +26,12 @@ assert{ a == b } ASSERTION FAILURE test/include_test_context_test.rb:15} ) end - + deny {e.message.include?("works with it too")} deny {e.message.include?("test_works_with_test_undercore")} end end - + it "works with it too" do begin assert{ 1 == 2 } @@ -43,12 +43,12 @@ assert{ 1 == 2 } ASSERTION FAILURE test/include_test_context_test.rb:36} ) end - + deny {e.message.include?("you can see test method")} deny {e.message.include?("test_works_with_test_undercore")} end end - + def test_works_with_test_undercore_too begin assert{ 1 == 2 } @@ -60,10 +60,10 @@ def test_works_with_test_undercore_too assert{ 1 == 2 } ASSERTION FAILURE test/include_test_context_test.rb:53} ) end - + deny {e.message.include?("you can see test method")} deny {e.message.include?("works with it too")} end end - + end diff --git a/test/rescuing_test.rb b/test/rescuing_test.rb index 512f95a..1fb47f0 100644 --- a/test/rescuing_test.rb +++ b/test/rescuing_test.rb @@ -2,10 +2,10 @@ require "wrong/adapters/minitest" describe "a helper for rescuing errors" do - + class RedError < StandardError; end class BlueError < StandardError; end - + it "returns the error that was raised" do assert{ rescuing{raise RedError.new}.is_a?(RedError) } end @@ -13,5 +13,5 @@ class BlueError < StandardError; end it "returns nil if nothing was raised" do assert{ rescuing{"x"}.nil? } end - + end diff --git a/test/string_comparison_test.rb b/test/string_comparison_test.rb index c08eaf4..cbb16c9 100644 --- a/test/string_comparison_test.rb +++ b/test/string_comparison_test.rb @@ -6,7 +6,7 @@ module Wrong describe StringComparison do StringComparison = Wrong::StringComparison # so Ruby 1.9.1 can find it - + before do # crank the window and prelude down for these tests @old_window = StringComparison.window diff --git a/test/verbose_test.rb b/test/verbose_test.rb index d438333..bd1ba7c 100644 --- a/test/verbose_test.rb +++ b/test/verbose_test.rb @@ -7,10 +7,10 @@ require "wrong/rainbow" describe "verbose assert" do - + include Wrong::Helpers include Wrong::D - + before do @m = Module.new do extend Wrong::Assert @@ -18,7 +18,7 @@ Wrong.config.verbose @color_enabled = Sickill::Rainbow.enabled end - + after do Wrong.config[:verbose] = nil Wrong.config[:color] = nil @@ -28,7 +28,7 @@ it "sets the verbose flag" do assert Wrong.config[:verbose] end - + it "prints the contents of a successful assert" do out = capturing { @m.assert { 2 + 2 == 4 } @@ -42,7 +42,7 @@ } assert_equal "basic math: ((2 + 2) == 4)\n", out end - + it "prints in color" do Wrong.config.color Sickill::Rainbow.enabled = true diff --git a/wrong.gemspec b/wrong.gemspec index 88a20ae..50017ab 100644 --- a/wrong.gemspec +++ b/wrong.gemspec @@ -28,5 +28,4 @@ helper methods, like rescuing, capturing, and d. s.add_dependency "ruby2ruby", ">= 2.0.1" s.add_dependency "sexp_processor", ">= 4.0" s.add_dependency "diff-lcs", "~> 1.2.0" - end