Browse files

Obeying the masters - no more bang-bang

  • Loading branch information...
1 parent 4e010e0 commit d2c9d0cef4647e50d0b3601bf9c254912dcd3aed @dchelimsky dchelimsky committed Nov 13, 2010
Showing with 22 additions and 20 deletions.
  1. +3 −3 lib/rspec/core/configuration.rb
  2. +15 −13 lib/rspec/core/example.rb
  3. +2 −2 lib/rspec/core/runner.rb
  4. +2 −2 spec/rspec/core/configuration_spec.rb
View
6 lib/rspec/core/configuration.rb
@@ -13,7 +13,7 @@ def self.add_setting(name, opts={})
else
define_method("#{name}=") {|val| settings[name] = val}
define_method(name) { settings.has_key?(name) ? settings[name] : opts[:default] }
- define_method("#{name}?") { !!(send name) }
+ define_method("#{name}?") { send name }
end
end
@@ -68,7 +68,7 @@ def initialize
#
# RSpec.configuration.foo=(value)
# RSpec.configuration.foo()
- # RSpec.configuration.foo?() # returns !!foo
+ # RSpec.configuration.foo?() # returns true if foo returns anything but nil or false
@myronmarston
RSpec member

This is a bit misleading...before #foo? returned true; now it just returns the value (which ruby treats as true if it's not nil or false).

@dchelimsky
RSpec member

Do you mean the comment is misleading? I should say "returns truthy"?

@myronmarston
RSpec member

Yes, I meant the comment is misleading. #foo? returns the same thing as #foo now...so maybe the comment could be something like this:

useful form for use in boolean expressons; returns the same value as #foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
#
# Intended for extension frameworks like rspec-rails, so they can add config
# settings that are domain specific. For example:
@@ -153,7 +153,7 @@ def color_enabled
end
def color_enabled?
- !!color_enabled
+ color_enabled
end
def color_enabled=(bool)
View
28 lib/rspec/core/example.rb
@@ -23,9 +23,7 @@ def example_group
@example_group_class
end
- def pending?
- !!pending
- end
+ alias_method :pending?, :pending
def run(example_group_instance, reporter)
@example_group_instance = example_group_instance
@@ -36,16 +34,7 @@ def run(example_group_instance, reporter)
begin
unless pending
with_pending_capture do
- with_around_hooks do
- begin
- run_before_each
- @example_group_instance.instance_eval(&@example_block)
- rescue Exception => e
- set_exception(e)
- ensure
- run_after_each
- end
- end
+ with_around_hooks &core_example
end
end
rescue Exception => e
@@ -58,6 +47,19 @@ def run(example_group_instance, reporter)
finish(reporter)
end
+ def core_example
+ lambda do
+ begin
+ run_before_each
+ @example_group_instance.instance_eval(&@example_block)
+ rescue Exception => e
+ set_exception(e)
+ ensure
+ run_after_each
+ end
+ end
+ end
+
def set_exception(exception)
@exception ||= exception
end
View
4 lib/rspec/core/runner.rb
@@ -23,8 +23,8 @@ def self.installed_at_exit?
end
def self.running_in_drb?
- (DRb.current_server rescue false) &&
- !!((DRb.current_server.uri) =~ /druby\:\/\/127.0.0.1\:/)
+ (DRb.current_server rescue false) &&
+ DRb.current_server.uri =~ /druby\:\/\/127.0.0.1\:/
end
def self.trap_interrupt
View
4 spec/rspec/core/configuration_spec.rb
@@ -241,12 +241,12 @@ def that_thing
describe "run_all_when_everything_filtered?" do
it "defaults to false" do
- config.run_all_when_everything_filtered?.should == false
+ config.run_all_when_everything_filtered?.should be_false
end
it "can be queried with question method" do
config.run_all_when_everything_filtered = true
- config.run_all_when_everything_filtered?.should == true
+ config.run_all_when_everything_filtered?.should be_true
end
end

0 comments on commit d2c9d0c

Please sign in to comment.