Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
move rspec_options from main to Spec (Spec.options)
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jul 12, 2008
1 parent 8c68a6a commit 3907d85
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bin/spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'spec'
exit ::Spec::Runner::CommandLine.run(rspec_options)
exit ::Spec::Runner::CommandLine.run(Spec.options)
17 changes: 15 additions & 2 deletions lib/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
module Spec
class << self
def run?
@run || rspec_options.examples_run?
@run || options.examples_run?
end

def run
return true if run?
result = rspec_options.run_examples
result = options.run_examples
@run = true
result
end
Expand All @@ -27,5 +27,18 @@ def run
def exit?
!Object.const_defined?(:Test) || Test::Unit.run?
end

def options
$rspec_options ||= begin; \
parser = ::Spec::Runner::OptionParser.new(STDERR, STDOUT); \
parser.order!(ARGV); \
$rspec_options = parser.options; \
end
$rspec_options
end

def init_options(options)
$rspec_options = options if $rspec_options.nil?
end
end
end
22 changes: 11 additions & 11 deletions lib/spec/example/example_group_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def set_description(*args)
def examples #:nodoc:
examples = example_objects.dup
add_method_examples(examples)
rspec_options.reverse ? examples.reverse : examples
Spec.options.reverse ? examples.reverse : examples
end

def number_of_examples #:nodoc:
Expand Down Expand Up @@ -252,11 +252,11 @@ def reset # :nodoc:

def register(&registration_binding_block)
@registration_binding_block = registration_binding_block
rspec_options.add_example_group self
Spec.options.add_example_group self
end

def unregister #:nodoc:
rspec_options.remove_example_group self
Spec.options.remove_example_group self
end

def registration_backtrace
Expand All @@ -278,8 +278,8 @@ def run_after_each(example)
private
def dry_run(examples)
examples.each do |example|
rspec_options.reporter.example_started(example)
rspec_options.reporter.example_finished(example)
Spec.options.reporter.example_started(example)
Spec.options.reporter.example_finished(example)
end
return true
end
Expand All @@ -302,7 +302,7 @@ def execute_examples(success, instance_variables, examples)

after_all_instance_variables = instance_variables
examples.each do |example_group_instance|
success &= example_group_instance.execute(rspec_options, instance_variables)
success &= example_group_instance.execute(Spec.options, instance_variables)
after_all_instance_variables = example_group_instance.instance_variable_hash
end
return [success, after_all_instance_variables]
Expand Down Expand Up @@ -335,15 +335,15 @@ def specified_examples?
end

def specified_examples
rspec_options.examples
Spec.options.examples
end

def reporter
rspec_options.reporter
Spec.options.reporter
end

def dry_run?
rspec_options.dry_run
Spec.options.dry_run
end

def example_objects
Expand Down Expand Up @@ -398,15 +398,15 @@ def before_parts_from_scope(scope)
case scope
when :each; before_each_parts
when :all; before_all_parts
when :suite; rspec_options.before_suite_parts
when :suite; Spec.options.before_suite_parts
end
end

def after_parts_from_scope(scope)
case scope
when :each; after_each_parts
when :all; after_all_parts
when :suite; rspec_options.after_suite_parts
when :suite; Spec.options.after_suite_parts
end
end

Expand Down
15 changes: 0 additions & 15 deletions lib/spec/extensions/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,6 @@ def share_as(name, &block)
raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
end
end

private

def rspec_options
$rspec_options ||= begin; \
parser = ::Spec::Runner::OptionParser.new(STDERR, STDOUT); \
parser.order!(ARGV); \
$rspec_options = parser.options; \
end
$rspec_options
end

def init_rspec_options(options)
$rspec_options = options if $rspec_options.nil?
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/spec/runner/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def run(instance_rspec_options)
# swapping of $rspec_options. That is all here to enable rspec to run against itself
# and maintain coverage in a single process. Therefore, DO NOT mess with this stuff
# unless you know what you are doing!
init_rspec_options(instance_rspec_options)
orig_rspec_options = rspec_options
Spec.init_options(instance_rspec_options)
orig_rspec_options = Spec.options
begin
$rspec_options = instance_rspec_options
return $rspec_options.run_examples
Expand Down
4 changes: 2 additions & 2 deletions lib/spec/runner/heckle_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def heckle_with

def heckle_method(class_name, method_name)
verify_constant(class_name)
heckle = @heckle_class.new(class_name, method_name, rspec_options)
heckle = @heckle_class.new(class_name, method_name, Spec.options)
heckle.validate
end

Expand All @@ -39,7 +39,7 @@ def heckle_class_or_module(class_or_module_name)

classes.each do |klass|
klass.instance_methods(false).each do |method_name|
heckle = @heckle_class.new(klass.name, method_name, rspec_options)
heckle = @heckle_class.new(klass.name, method_name, Spec.options)
heckle.validate
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/runner/spec_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize
def spec_name_for(file, line_number)
best_match.clear
file = File.expand_path(file)
rspec_options.example_groups.each do |example_group|
Spec.options.example_groups.each do |example_group|
consider_example_groups_for_best_match example_group, file, line_number

example_group.examples.each do |example|
Expand Down
3 changes: 1 addition & 2 deletions lib/spec/story/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module Story
module Runner
class << self
def run_options # :nodoc:
rspec_options
# @run_options ||= ::Spec::Runner::OptionParser.parse(ARGV, $stderr, $stdout)
Spec.options
end

def story_runner # :nodoc:
Expand Down
4 changes: 2 additions & 2 deletions spec/spec/example/example_group_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ def initialize(*args, &block)
it "should register ExampleGroup by default" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
end
rspec_options.example_groups.should include(example_group)
Spec.options.example_groups.should include(example_group)
end

it "should enable unregistering of ExampleGroups" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
unregister
end
rspec_options.example_groups.should_not include(example_group)
Spec.options.example_groups.should_not include(example_group)
end

after(:each) do
Expand Down
9 changes: 2 additions & 7 deletions spec/spec/extensions/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ module Extensions
$rspec_story_steps = @original_rspec_story_steps
end

it "should create an Options object" do
@main.send(:rspec_options).should be_instance_of(Spec::Runner::Options)
@main.send(:rspec_options).should === $rspec_options
end

specify {@main.should respond_to(:describe)}
specify {@main.should respond_to(:context)}

Expand All @@ -30,15 +25,15 @@ module Extensions

it "should registered ExampleGroups by default" do
example_group = @main.describe("The ExampleGroup") do end
rspec_options.example_groups.should include(example_group)
Spec.options.example_groups.should include(example_group)
end

it "should not run unregistered ExampleGroups" do
example_group = @main.describe("The ExampleGroup") do
unregister
end

rspec_options.example_groups.should_not include(example_group)
Spec.options.example_groups.should_not include(example_group)
end

it "should create a shared ExampleGroup with share_examples_for" do
Expand Down
16 changes: 8 additions & 8 deletions spec/spec/runner/heckle_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ def four; end
end

it "should heckle all methods in all classes in a module" do
@heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Zap", "three", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Zap", "four", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec.options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec.options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Zap", "three", Spec.options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Zap", "four", Spec.options).and_return(@heckle)

heckle_runner = Spec::Runner::HeckleRunner.new("Foo", @heckle_class)
heckle_runner.heckle_with
end

it "should heckle all methods in a class" do
@heckle_class.should_receive(:new).with("Foo::Bar", "one", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "one", Spec.options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec.options).and_return(@heckle)

heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar", @heckle_class)
heckle_runner.heckle_with
Expand All @@ -46,14 +46,14 @@ def four; end
end

it "should heckle specific method in a class (with #)" do
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec.options).and_return(@heckle)

heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar#two", @heckle_class)
heckle_runner.heckle_with
end

it "should heckle specific method in a class (with .)" do
@heckle_class.should_receive(:new).with("Foo::Bar", "two", rspec_options).and_return(@heckle)
@heckle_class.should_receive(:new).with("Foo::Bar", "two", Spec.options).and_return(@heckle)

heckle_runner = Spec::Runner::HeckleRunner.new("Foo::Bar.two", @heckle_class)
heckle_runner.heckle_with
Expand Down
2 changes: 1 addition & 1 deletion spec/spec/runner/output_one_time_fixture_runner.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dir = File.dirname(__FILE__)
require "#{dir}/../../spec_helper"

triggering_double_output = rspec_options
triggering_double_output = Spec.options
options = Spec::Runner::OptionParser.parse(
["#{dir}/output_one_time_fixture.rb"], $stderr, $stdout
)
Expand Down

0 comments on commit 3907d85

Please sign in to comment.