Skip to content

Commit

Permalink
fix issue sconover#6
Browse files Browse the repository at this point in the history
  • Loading branch information
alexch committed May 18, 2011
1 parent a92b456 commit 4de18d4
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 8 deletions.
21 changes: 20 additions & 1 deletion lib/wrong/adapters/rspec.rb
Expand Up @@ -28,14 +28,33 @@ module RSpec
module Core
class ExampleGroup
include Wrong

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

elsif Object.const_defined? :Spec
# RSpec 1
Spec::Runner.configure do |config|
Expand Down
17 changes: 11 additions & 6 deletions lib/wrong/config.rb
@@ -1,6 +1,7 @@
require "wrong/chunk"

module Wrong

def self.load_config
settings = begin
Chunk.read_here_or_higher(".wrong")
Expand All @@ -20,7 +21,11 @@ def self.config=(new_config)
end

class Config < Hash
def initialize(string = nil)

class ConfigError < RuntimeError
end

def initialize(string = nil)
self[:aliases] = {:assert => [:assert], :deny => [:deny]}
if string
instance_eval string.gsub(/^(.*=)/, "self.\\1")
Expand All @@ -35,18 +40,18 @@ def method_missing(name, value = true)
self[name.to_sym] = value
end

def alias_assert_or_deny(valence, extra_name)
def alias_assert_or_deny(valence, extra_name, options)
Wrong::Assert.send(:alias_method, extra_name, valence)
new_method_name = extra_name.to_sym
self[:aliases][valence] << new_method_name unless self[:aliases][valence].include?(new_method_name)
end

def alias_assert(method_name)
alias_assert_or_deny(:assert, method_name)
def alias_assert(method_name, options = {})
alias_assert_or_deny(:assert, method_name, options)
end

def alias_deny(method_name)
alias_assert_or_deny(:deny, method_name)
def alias_deny(method_name, options = {})
alias_assert_or_deny(:deny, method_name, options)
end

def assert_method_names
Expand Down
32 changes: 32 additions & 0 deletions test/adapters/rspec2/failing_spec.rb
Expand Up @@ -17,6 +17,7 @@
require 'rspec/autorun'
require "wrong/adapters/rspec"

# these first ones should pass, since they describe how Wrong works inside the RSpec ecosystem
describe "wrong's failure" do
it "is an RSpec exception" do
e = rescuing {
Expand All @@ -26,6 +27,37 @@
end
end

describe "alias_assert" do
it "works for an innocuous name" do
e = rescuing {
Wrong.config.alias_assert :allow
}
e.should be_nil
end

describe ":expect" do
it "fails if RSpec is active" do
e = rescuing {
Wrong.config.alias_assert :expect
}
e.should be_a(Wrong::Config::ConfigError)
end

it "works if we pass :override => true" do
e = rescuing {
Wrong.config.alias_assert :expect, :override => true
}
e.should be_nil

e = rescuing {
expect { false }
}
e.should_not be_nil
e.should be_a(RSpec::Expectations::ExpectationNotMetError)
end
end
end

describe "arithmetic" do
it "should not work like this" do
assert { 2 + 2 == 5 }
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test/adapters/rspec2/vendor/cache/spruz-0.2.6.gem
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion test/adapters/rspec_test.rb
Expand Up @@ -36,7 +36,7 @@
(rspec_version == 1 || RUBY_VERSION =~ /^1\.8\./ || RUBY_VERSION == '1.9.1' ? nil : 1) # RSpec v1 exits with 0 on failure :-(
end

assert { spec_output.include? "2 examples, 1 failure" }
assert { spec_output.include? "1 failure" }
assert { spec_output.include? "Expected ((2 + 2) == 5), but" }
end
end
Expand Down

0 comments on commit 4de18d4

Please sign in to comment.