rspec-core 2.0.0.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/.treasure_map.rb +23 -0
  4. data/License.txt +22 -0
  5. data/README.markdown +9 -0
  6. data/Rakefile +76 -0
  7. data/TODO.markdown +16 -0
  8. data/VERSION +1 -0
  9. data/VERSION.yml +5 -0
  10. data/bin/rspec +12 -0
  11. data/cucumber.yml +2 -0
  12. data/example_specs/failing/README.txt +7 -0
  13. data/example_specs/failing/diffing_spec.rb +36 -0
  14. data/example_specs/failing/failing_implicit_docstrings_example.rb +19 -0
  15. data/example_specs/failing/failure_in_after.rb +10 -0
  16. data/example_specs/failing/failure_in_before.rb +10 -0
  17. data/example_specs/failing/mocking_example.rb +40 -0
  18. data/example_specs/failing/mocking_with_flexmock.rb +26 -0
  19. data/example_specs/failing/mocking_with_mocha.rb +25 -0
  20. data/example_specs/failing/mocking_with_rr.rb +27 -0
  21. data/example_specs/failing/partial_mock_example.rb +20 -0
  22. data/example_specs/failing/pending_example.rb +9 -0
  23. data/example_specs/failing/predicate_example.rb +34 -0
  24. data/example_specs/failing/raising_example.rb +47 -0
  25. data/example_specs/failing/spec_helper.rb +3 -0
  26. data/example_specs/failing/syntax_error_example.rb +7 -0
  27. data/example_specs/failing/team_spec.rb +44 -0
  28. data/example_specs/failing/timeout_behaviour.rb +7 -0
  29. data/example_specs/passing/custom_formatter.rb +12 -0
  30. data/example_specs/passing/custom_matchers.rb +54 -0
  31. data/example_specs/passing/dynamic_spec.rb +9 -0
  32. data/example_specs/passing/file_accessor.rb +19 -0
  33. data/example_specs/passing/file_accessor_spec.rb +38 -0
  34. data/example_specs/passing/filtered_formatter.rb +18 -0
  35. data/example_specs/passing/filtered_formatter_example.rb +31 -0
  36. data/example_specs/passing/greeter_spec.rb +31 -0
  37. data/example_specs/passing/helper_method_example.rb +14 -0
  38. data/example_specs/passing/implicit_docstrings_example.rb +18 -0
  39. data/example_specs/passing/io_processor.rb +8 -0
  40. data/example_specs/passing/io_processor_spec.rb +21 -0
  41. data/example_specs/passing/mocking_example.rb +27 -0
  42. data/example_specs/passing/multi_threaded_example_group_runner.rb +26 -0
  43. data/example_specs/passing/nested_classes_example.rb +36 -0
  44. data/example_specs/passing/options_example.rb +31 -0
  45. data/example_specs/passing/options_formatter.rb +20 -0
  46. data/example_specs/passing/partial_mock_example.rb +29 -0
  47. data/example_specs/passing/pending_example.rb +20 -0
  48. data/example_specs/passing/predicate_example.rb +27 -0
  49. data/example_specs/passing/shared_example_group_example.rb +81 -0
  50. data/example_specs/passing/shared_stack_examples.rb +36 -0
  51. data/example_specs/passing/simple_matcher_example.rb +31 -0
  52. data/example_specs/passing/spec_helper.rb +14 -0
  53. data/example_specs/passing/stack.rb +36 -0
  54. data/example_specs/passing/stack_spec.rb +64 -0
  55. data/example_specs/passing/stack_spec_with_nested_example_groups.rb +67 -0
  56. data/example_specs/passing/stubbing_example.rb +69 -0
  57. data/example_specs/passing/yielding_example.rb +33 -0
  58. data/example_specs/ruby1.9.compatibility/access_to_constants_spec.rb +85 -0
  59. data/features-pending/command_line/line_number_option.feature +56 -0
  60. data/features-pending/command_line/line_number_option_with_example_with_no_name.feature +22 -0
  61. data/features-pending/example_groups/example_group_with_should_methods.feature +29 -0
  62. data/features-pending/example_groups/implicit_docstrings.feature +59 -0
  63. data/features-pending/example_groups/nested_groups.feature +32 -0
  64. data/features-pending/expectations/expect_change.feature +65 -0
  65. data/features-pending/expectations/expect_error.feature +44 -0
  66. data/features-pending/extensions/custom_example_group.feature +19 -0
  67. data/features-pending/formatters/custom_formatter.feature +30 -0
  68. data/features-pending/heckle/heckle.feature +56 -0
  69. data/features-pending/interop/examples_and_tests_together.feature +80 -0
  70. data/features-pending/interop/rspec_output.feature +25 -0
  71. data/features-pending/interop/test_but_not_test_unit.feature +26 -0
  72. data/features-pending/interop/test_case_with_should_methods.feature +46 -0
  73. data/features-pending/matchers/define_diffable_matcher.feature +26 -0
  74. data/features-pending/matchers/define_matcher.feature +179 -0
  75. data/features-pending/matchers/define_matcher_with_fluent_interface.feature +27 -0
  76. data/features-pending/mocks/mix_stubs_and_mocks.feature +22 -0
  77. data/features-pending/mocks/stub_implementation.feature +26 -0
  78. data/features-pending/pending/pending_examples.feature +81 -0
  79. data/features-pending/runner/specify_line_number.feature +32 -0
  80. data/features/before_and_after_blocks/before_and_after_blocks.feature +169 -0
  81. data/features/expectations/customized_message.feature +54 -0
  82. data/features/matchers/define_matcher_outside_rspec.feature +39 -0
  83. data/features/mock_framework_integration/use_flexmock.feature +23 -0
  84. data/features/mock_framework_integration/use_mocha.feature +23 -0
  85. data/features/mock_framework_integration/use_rr.feature +23 -0
  86. data/features/mock_framework_integration/use_rspec.feature +23 -0
  87. data/features/step_definitions/running_rspec_steps.rb +35 -0
  88. data/features/subject/explicit_subject.feature +31 -0
  89. data/features/subject/implicit_subject.feature +31 -0
  90. data/features/support/env.rb +82 -0
  91. data/features/support/matchers/smart_match.rb +14 -0
  92. data/lib/rspec/autorun.rb +2 -0
  93. data/lib/rspec/core.rb +38 -0
  94. data/lib/rspec/core/backward_compatibility.rb +9 -0
  95. data/lib/rspec/core/command_line_options.rb +60 -0
  96. data/lib/rspec/core/configuration.rb +222 -0
  97. data/lib/rspec/core/deprecation.rb +47 -0
  98. data/lib/rspec/core/example.rb +113 -0
  99. data/lib/rspec/core/example_group.rb +239 -0
  100. data/lib/rspec/core/example_group_subject.rb +77 -0
  101. data/lib/rspec/core/formatters.rb +16 -0
  102. data/lib/rspec/core/formatters/base_formatter.rb +123 -0
  103. data/lib/rspec/core/formatters/base_text_formatter.rb +139 -0
  104. data/lib/rspec/core/formatters/documentation_formatter.rb +84 -0
  105. data/lib/rspec/core/formatters/progress_formatter.rb +36 -0
  106. data/lib/rspec/core/kernel_extensions.rb +15 -0
  107. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +13 -0
  108. data/lib/rspec/core/mocking/with_flexmock.rb +25 -0
  109. data/lib/rspec/core/mocking/with_mocha.rb +22 -0
  110. data/lib/rspec/core/mocking/with_rr.rb +26 -0
  111. data/lib/rspec/core/mocking/with_rspec.rb +21 -0
  112. data/lib/rspec/core/rake_task.rb +88 -0
  113. data/lib/rspec/core/runner.rb +66 -0
  114. data/lib/rspec/core/shared_behaviour.rb +41 -0
  115. data/lib/rspec/core/shared_behaviour_kernel_extensions.rb +31 -0
  116. data/lib/rspec/core/version.rb +16 -0
  117. data/lib/rspec/core/world.rb +105 -0
  118. data/rspec-core.gemspec +204 -0
  119. data/script/console +8 -0
  120. data/spec/resources/example_classes.rb +67 -0
  121. data/spec/rspec/core/command_line_options_spec.rb +63 -0
  122. data/spec/rspec/core/configuration_spec.rb +171 -0
  123. data/spec/rspec/core/example_group_spec.rb +351 -0
  124. data/spec/rspec/core/example_group_subject_spec.rb +67 -0
  125. data/spec/rspec/core/example_spec.rb +67 -0
  126. data/spec/rspec/core/formatters/base_formatter_spec.rb +105 -0
  127. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +5 -0
  128. data/spec/rspec/core/formatters/progress_formatter_spec.rb +29 -0
  129. data/spec/rspec/core/kernel_extensions_spec.rb +13 -0
  130. data/spec/rspec/core/mocha_spec.rb +29 -0
  131. data/spec/rspec/core/resources/a_bar.rb +0 -0
  132. data/spec/rspec/core/resources/a_foo.rb +0 -0
  133. data/spec/rspec/core/resources/a_spec.rb +1 -0
  134. data/spec/rspec/core/resources/custom_example_group_runner.rb +14 -0
  135. data/spec/rspec/core/resources/example_classes.rb +67 -0
  136. data/spec/rspec/core/resources/utf8_encoded.rb +8 -0
  137. data/spec/rspec/core/runner_spec.rb +34 -0
  138. data/spec/rspec/core/shared_behaviour_spec.rb +185 -0
  139. data/spec/rspec/core/world_spec.rb +167 -0
  140. data/spec/rspec/core_spec.rb +35 -0
  141. data/spec/ruby_forker.rb +13 -0
  142. data/spec/spec_helper.rb +72 -0
  143. metadata +219 -0
@@ -0,0 +1,23 @@
1
+ Feature: mock with flexmock
2
+
3
+ As an RSpec user who likes to mock
4
+ I want to be able to use flexmock
5
+
6
+ Scenario: Mock with flexmock
7
+ Given a file named "flexmock_example_spec.rb" with:
8
+ """
9
+ Rspec::Core.configure do |config|
10
+ config.mock_framework = :flexmock
11
+ end
12
+
13
+ describe "plugging in flexmock" do
14
+ it "allows flexmock to be used" do
15
+ target = Object.new
16
+ flexmock(target).should_receive(:foo).once
17
+ target.foo
18
+ end
19
+ end
20
+ """
21
+ When I run "spec flexmock_example_spec.rb"
22
+ Then the stdout should match "1 example, 0 failures"
23
+ And the exit code should be 0
@@ -0,0 +1,23 @@
1
+ Feature: mock with mocha
2
+
3
+ As an RSpec user who likes to mock
4
+ I want to be able to use mocha
5
+
6
+ Scenario: Mock with mocha
7
+ Given a file named "mocha_example_spec.rb" with:
8
+ """
9
+ Rspec::Core.configure do |config|
10
+ config.mock_framework = :mocha
11
+ end
12
+
13
+ describe "plugging in mocha" do
14
+ it "allows mocha to be used" do
15
+ target = Object.new
16
+ target.expects(:foo).once
17
+ target.foo
18
+ end
19
+ end
20
+ """
21
+ When I run "spec mocha_example_spec.rb"
22
+ Then the stdout should match "1 example, 0 failures"
23
+ And the exit code should be 0
@@ -0,0 +1,23 @@
1
+ Feature: mock with rr
2
+
3
+ As an RSpec user who likes to mock
4
+ I want to be able to use rr
5
+
6
+ Scenario: Mock with rr
7
+ Given a file named "rr_example_spec.rb" with:
8
+ """
9
+ Rspec::Core.configure do |config|
10
+ config.mock_framework = :rr
11
+ end
12
+
13
+ describe "plugging in rr" do
14
+ it "allows rr to be used" do
15
+ target = Object.new
16
+ mock(target).foo
17
+ target.foo
18
+ end
19
+ end
20
+ """
21
+ When I run "spec rr_example_spec.rb"
22
+ Then the stdout should match "1 example, 0 failures"
23
+ And the exit code should be 0
@@ -0,0 +1,23 @@
1
+ Feature: mock with rspec
2
+
3
+ As an RSpec user who likes to mock
4
+ I want to be able to use rspec
5
+
6
+ Scenario: Mock with rspec
7
+ Given a file named "rspec_example_spec.rb" with:
8
+ """
9
+ Rspec::Core.configure do |config|
10
+ config.mock_framework = :rspec
11
+ end
12
+
13
+ describe "plugging in rspec" do
14
+ it "allows rspec to be used" do
15
+ target = mock('target')
16
+ target.should_receive(:foo)
17
+ target.foo
18
+ end
19
+ end
20
+ """
21
+ When I run "spec rspec_example_spec.rb"
22
+ Then the stdout should match "1 example, 0 failures"
23
+ And the exit code should be 0
@@ -0,0 +1,35 @@
1
+ Given %r{^a file named "([^"]+)" with:$} do |file_name, code|
2
+ create_file(file_name, code)
3
+ end
4
+
5
+ When %r{^I run "r?spec ([^"]+)"$} do |file_and_args|
6
+ spec(file_and_args)
7
+ end
8
+
9
+ When %r{^I run "ruby ([^"]+)"$} do |file_and_args|
10
+ ruby(file_and_args)
11
+ end
12
+
13
+ Then /^the (.*) should match (.*)$/ do |stream, string_or_regex|
14
+ written = case(stream)
15
+ when 'stdout' then last_stdout
16
+ when 'stderr' then last_stderr
17
+ else raise "Unknown stream: #{stream}"
18
+ end
19
+ written.should smart_match(string_or_regex)
20
+ end
21
+
22
+ Then /^the (.*) should not match (.*)$/ do |stream, string_or_regex|
23
+ written = case(stream)
24
+ when 'stdout' then last_stdout
25
+ when 'stderr' then last_stderr
26
+ else raise "Unknown stream: #{stream}"
27
+ end
28
+ written.should_not smart_match(string_or_regex)
29
+ end
30
+
31
+ Then /^the exit code should be (\d+)$/ do |exit_code|
32
+ if last_exit_code != exit_code.to_i
33
+ raise "Did not exit with #{exit_code}, but with #{last_exit_code}. Standard error:\n#{last_stderr}"
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ Feature: explicit subject
2
+
3
+ You can override the implicit subject using the subject() method.
4
+
5
+ Scenario: subject in top level group
6
+ Given a file named "top_level_subject_spec.rb" with:
7
+ """
8
+ describe Array, "with some elements" do
9
+ subject { [1,2,3] }
10
+ it "should have the prescribed elements" do
11
+ subject.should == [1,2,3]
12
+ end
13
+ end
14
+ """
15
+ When I run "spec top_level_subject_spec.rb"
16
+ Then the stdout should match "1 example, 0 failures"
17
+
18
+ Scenario: subject in a nested group
19
+ Given a file named "nested_subject_spec.rb" with:
20
+ """
21
+ describe Array do
22
+ subject { [1,2,3] }
23
+ describe "with some elements" do
24
+ it "should have the prescribed elements" do
25
+ subject.should == [1,2,3]
26
+ end
27
+ end
28
+ end
29
+ """
30
+ When I run "spec nested_subject_spec.rb"
31
+ Then the stdout should match "1 example, 0 failures"
@@ -0,0 +1,31 @@
1
+ Feature: implicit subject
2
+
3
+ The first argument to the outermost example group block is
4
+ made available to each example as an implicit subject of
5
+ that example.
6
+
7
+ Scenario: subject in top level group
8
+ Given a file named "top_level_subject_spec.rb" with:
9
+ """
10
+ describe Array, "when first created" do
11
+ it "should be empty" do
12
+ subject.should == []
13
+ end
14
+ end
15
+ """
16
+ When I run "spec top_level_subject_spec.rb"
17
+ Then the stdout should match "1 example, 0 failures"
18
+
19
+ Scenario: subject in a nested group
20
+ Given a file named "nested_subject_spec.rb" with:
21
+ """
22
+ describe Array do
23
+ describe "when first created" do
24
+ it "should be empty" do
25
+ subject.should == []
26
+ end
27
+ end
28
+ end
29
+ """
30
+ When I run "spec nested_subject_spec.rb"
31
+ Then the stdout should match "1 example, 0 failures"
@@ -0,0 +1,82 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "/../../lib")
2
+ $:.unshift File.join(File.dirname(__FILE__), "/../../../expectations/lib")
3
+
4
+ require 'forwardable'
5
+ require 'tempfile'
6
+ require 'spec/ruby_forker'
7
+ require 'features/support/matchers/smart_match'
8
+
9
+
10
+ class RspecWorld
11
+ include Rspec::Expectations
12
+ include Rspec::Matchers
13
+ include RubyForker
14
+
15
+ extend Forwardable
16
+ def_delegators RspecWorld, :working_dir, :spec_command
17
+
18
+ def self.working_dir
19
+ @working_dir ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../tmp/cucumber-generated-files"))
20
+ end
21
+
22
+ def self.spec_command
23
+ @spec_command ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../bin/rspec"))
24
+ end
25
+
26
+ RSPEC_LIB = File.expand_path(File.join(working_dir, "/../../lib"))
27
+ RSPEC_EXPECTATIONS_LIB = File.expand_path(File.join(working_dir, "/../../../expectations/lib"))
28
+ RSPEC_MOCKS_LIB = File.expand_path(File.join(working_dir, "/../../../mocks/lib"))
29
+
30
+ def spec(args)
31
+ ruby("#{spec_command} #{args}")
32
+ end
33
+
34
+ def create_file(file_name, contents)
35
+ file_path = File.join(working_dir, file_name)
36
+ File.open(file_path, "w") { |f| f << contents }
37
+ end
38
+
39
+ def last_stdout
40
+ @stdout
41
+ end
42
+
43
+ def last_stderr
44
+ @stderr
45
+ end
46
+
47
+ def last_exit_code
48
+ @exit_code
49
+ end
50
+
51
+ def rspec_libs
52
+ result = "-I #{RSPEC_LIB}"
53
+ if File.directory?(RSPEC_EXPECTATIONS_LIB)
54
+ result << " -I #{RSPEC_EXPECTATIONS_LIB}"
55
+ end
56
+ if File.directory?(RSPEC_MOCKS_LIB)
57
+ result << " -I #{RSPEC_MOCKS_LIB}"
58
+ end
59
+ result
60
+ end
61
+
62
+ # it seems like this, and the last_* methods, could be moved into RubyForker-- is that being used anywhere but the features?
63
+ def ruby(args)
64
+ stderr_file = Tempfile.new('rspec')
65
+ stderr_file.close
66
+ Dir.chdir(working_dir) do
67
+ @stdout = super("#{rspec_libs} #{args}", stderr_file.path)
68
+ end
69
+ @stderr = IO.read(stderr_file.path)
70
+ @exit_code = $?.to_i
71
+ end
72
+
73
+ end
74
+
75
+ Before do
76
+ FileUtils.rm_rf RspecWorld.working_dir if test ?d, RspecWorld.working_dir
77
+ FileUtils.mkdir_p RspecWorld.working_dir
78
+ end
79
+
80
+ World do
81
+ RspecWorld.new
82
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec/expectations'
2
+
3
+ Rspec::Matchers.define :smart_match do |expected|
4
+ match do |actual|
5
+ case expected
6
+ when /^\/.*\/?$/
7
+ actual =~ eval(expected)
8
+ when /^".*"$/
9
+ actual.index(eval(expected))
10
+ else
11
+ false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec/core'
2
+ Rspec::Core.configuration.autorun!
@@ -0,0 +1,38 @@
1
+ require 'rspec/core/deprecation'
2
+ require 'rspec/core/mocking/with_absolutely_nothing'
3
+ require 'rspec/core/world'
4
+ require 'rspec/core/configuration'
5
+ require 'rspec/core/command_line_options'
6
+ require 'rspec/core/runner'
7
+ require 'rspec/core/example'
8
+ require 'rspec/core/kernel_extensions'
9
+ require 'rspec/core/shared_behaviour'
10
+ require 'rspec/core/example_group_subject'
11
+ require 'rspec/core/example_group'
12
+ require 'rspec/core/formatters'
13
+ require 'rspec/core/backward_compatibility'
14
+ require 'rspec/core/version'
15
+
16
+ module Rspec
17
+ module Core
18
+
19
+ def self.install_directory
20
+ @install_directory ||= File.expand_path(File.dirname(__FILE__))
21
+ puts "@install_directory => #{@install_directory}"
22
+ @install_directory
23
+ end
24
+
25
+ def self.configuration
26
+ @configuration ||= Rspec::Core::Configuration.new
27
+ end
28
+
29
+ def self.configure
30
+ yield configuration if block_given?
31
+ end
32
+
33
+ def self.world
34
+ @world ||= Rspec::Core::World.new
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module Rspec
2
+ module Core
3
+ class Configuration
4
+ def mock_with(use_me_to_mock)
5
+ self.mock_framework = use_me_to_mock
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,60 @@
1
+ require 'optparse'
2
+ # http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
3
+
4
+ module Rspec
5
+ module Core
6
+
7
+ class CommandLineOptions
8
+
9
+ attr_reader :args, :options
10
+
11
+ def self.parse(args)
12
+ cli_options = new(args)
13
+ cli_options.parse
14
+ cli_options
15
+ end
16
+
17
+ def initialize(args)
18
+ @args = args
19
+ @options = {}
20
+ end
21
+
22
+ def files_to_run
23
+ options[:files_to_run]
24
+ end
25
+
26
+ def parse
27
+ possible_files = OptionParser.new do |opts|
28
+ opts.banner = "Usage: rspec [options] [files or directories]"
29
+
30
+ opts.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output') do |o|
31
+ options[:color_enabled] = o
32
+ end
33
+
34
+ opts.on('-f', '--formatter [FORMATTER]', 'Choose an optional formatter') do |o|
35
+ options[:formatter] = o
36
+ end
37
+
38
+ opts.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
39
+ options[:profile_examples] = o
40
+ end
41
+
42
+ opts.on_tail('-h', '--help', "You're looking at it.") do
43
+ puts opts
44
+ end
45
+ end.parse!(@args)
46
+
47
+ options[:files_to_run] = possible_files
48
+ options
49
+ end
50
+
51
+ def apply(config)
52
+ options.each do |key, value|
53
+ config.send("#{key}=", value)
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,222 @@
1
+ module Rspec
2
+ module Core
3
+ class Configuration
4
+ # Regex patterns to scrub backtrace with
5
+ attr_reader :backtrace_clean_patterns
6
+
7
+ # All of the defined before/after blocks setup in the configuration
8
+ attr_reader :before_and_afters
9
+
10
+ # Allows you to control what examples are ran by filtering
11
+ attr_reader :filter
12
+
13
+ attr_reader :exclusion_filter
14
+
15
+ # Modules that will be included or extended based on given filters
16
+ attr_reader :include_or_extend_modules
17
+
18
+ # Run all examples if the run is filtered, and no examples were found. Normally this is what you want -
19
+ # when using focused examples for instance. Defaults to true
20
+ attr_accessor :run_all_when_everything_filtered
21
+
22
+ # Enable verbose interal logging of the framework - defaults to false
23
+ attr_accessor :trace
24
+
25
+ attr_reader :options
26
+
27
+ def initialize
28
+ @run_all_when_everything_filtered = true
29
+ @before_and_afters = { :before => { :each => [], :all => [], :suite => [] }, :after => { :each => [], :all => [], :suite => [] } }
30
+ @include_or_extend_modules = []
31
+ @filter, @exclusion_filter = nil, nil
32
+ @options = default_options
33
+ @backtrace_clean_patterns = []
34
+ end
35
+
36
+ def default_options
37
+ {
38
+ :color_enabled => false,
39
+ :mock_framework => nil,
40
+ :profile_examples => false,
41
+ :files_to_run => [],
42
+ :filename_pattern => '**/*_spec.rb',
43
+ :formatter_class => Rspec::Core::Formatters::ProgressFormatter,
44
+ :backtrace_clean_patterns => [/\/lib\/ruby\//,
45
+ /bin\/rcov:/,
46
+ /vendor\/rails/,
47
+ /bin\/rspec/,
48
+ /bin\/spec/,
49
+ /lib\/rspec\/core/,
50
+ /lib\/rspec\/expectations/,
51
+ /lib\/rspec\/mocks/]
52
+ }
53
+ end
54
+
55
+ def cleaned_from_backtrace?(line)
56
+ options[:backtrace_clean_patterns].any? { |regex| line =~ regex }
57
+ end
58
+
59
+ def mock_framework=(use_me_to_mock)
60
+ options[:mock_framework] = use_me_to_mock
61
+
62
+ mock_framework_class = case use_me_to_mock.to_s
63
+ when /rspec/i
64
+ require 'rspec/core/mocking/with_rspec'
65
+ Rspec::Core::Mocking::WithRspec
66
+ when /mocha/i
67
+ require 'rspec/core/mocking/with_mocha'
68
+ Rspec::Core::Mocking::WithMocha
69
+ when /rr/i
70
+ require 'rspec/core/mocking/with_rr'
71
+ Rspec::Core::Mocking::WithRR
72
+ when /flexmock/i
73
+ require 'rspec/core/mocking/with_flexmock'
74
+ Rspec::Core::Mocking::WithFlexmock
75
+ else
76
+ require 'rspec/core/mocking/with_absolutely_nothing'
77
+ Rspec::Core::Mocking::WithAbsolutelyNothing
78
+ end
79
+
80
+ options[:mock_framework_class] = mock_framework_class
81
+ Rspec::Core::ExampleGroup.send(:include, mock_framework_class)
82
+ end
83
+
84
+ def mock_framework
85
+ options[:mock_framework]
86
+ end
87
+
88
+ def filename_pattern
89
+ options[:filename_pattern]
90
+ end
91
+
92
+ def filename_pattern=(new_pattern)
93
+ options[:filename_pattern] = new_pattern
94
+ end
95
+
96
+ def color_enabled=(on_or_off)
97
+ options[:color_enabled] = on_or_off
98
+ end
99
+
100
+ def color_enabled?
101
+ options[:color_enabled]
102
+ end
103
+
104
+ # Enable profiling of example run - defaults to false
105
+ def profile_examples
106
+ options[:profile_examples]
107
+ end
108
+
109
+ def profile_examples=(profile)
110
+ options[:profile_examples] = on_or_off
111
+ end
112
+
113
+ def formatter_class
114
+ options[:formatter_class]
115
+ end
116
+
117
+ def formatter=(formatter_to_use)
118
+ formatter_class = case formatter_to_use.to_s
119
+ when /doc/, 's'
120
+ Rspec::Core::Formatters::DocumentationFormatter
121
+ when 'progress'
122
+ Rspec::Core::Formatters::ProgressFormatter
123
+ else
124
+ raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?."
125
+ end
126
+ options[:formatter_class] = formatter_class
127
+ end
128
+
129
+ def formatter
130
+ @formatter ||= formatter_class.new
131
+ end
132
+
133
+ def files_to_run
134
+ options[:files_to_run]
135
+ end
136
+
137
+ def files_to_run=(*files)
138
+ files.flatten!
139
+
140
+ result = []
141
+ files.each do |file|
142
+ if File.directory?(file)
143
+ filename_pattern.split(",").each do |pattern|
144
+ result += Dir[File.expand_path("#{file}/#{pattern.strip}")]
145
+ end
146
+ elsif File.file?(file)
147
+ result << file
148
+ else
149
+ raise "File or directory not found: #{file}"
150
+ end
151
+ end
152
+
153
+ options[:files_to_run] = result
154
+ end
155
+
156
+ # E.g. alias_example_to :crazy_slow, :speed => 'crazy_slow' defines
157
+ # crazy_slow as an example variant that has the crazy_slow speed option
158
+ def alias_example_to(new_name, extra_options={})
159
+ Rspec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
160
+ end
161
+
162
+ def autorun!
163
+ Rspec::Core::Runner.autorun
164
+ end
165
+
166
+ def filter_run(options={})
167
+ @filter = options
168
+ end
169
+
170
+ def run_all_when_everything_filtered?
171
+ @run_all_when_everything_filtered
172
+ end
173
+
174
+ # Where does output go? For now $stdout
175
+ def output
176
+ $stdout
177
+ end
178
+
179
+ def puts(msg='')
180
+ output.puts(msg)
181
+ end
182
+
183
+ def parse_command_line_args(args)
184
+ @command_line_options = Rspec::Core::CommandLineOptions.parse(args)
185
+ end
186
+
187
+ def include(mod, options={})
188
+ include_or_extend_modules << [:include, mod, options]
189
+ end
190
+
191
+ def extend(mod, options={})
192
+ include_or_extend_modules << [:extend, mod, options]
193
+ end
194
+
195
+ def find_modules(group)
196
+ include_or_extend_modules.select do |include_or_extend, mod, options|
197
+ options.all? do |filter_on, filter|
198
+ Rspec::Core.world.apply_condition(filter_on, filter, group.metadata)
199
+ end
200
+ end
201
+ end
202
+
203
+ def before(each_or_all=:each, options={}, &block)
204
+ before_and_afters[:before][each_or_all] << [options, block]
205
+ end
206
+
207
+ def after(each_or_all=:each, options={}, &block)
208
+ before_and_afters[:after][each_or_all] << [options, block]
209
+ end
210
+
211
+ def find_before_or_after(desired_before_or_after, desired_each_or_all, group)
212
+ before_and_afters[desired_before_or_after][desired_each_or_all].select do |options, block|
213
+ options.all? do |filter_on, filter|
214
+ Rspec::Core.world.apply_condition(filter_on, filter, group.metadata)
215
+ end
216
+ end.map { |options, block| block }
217
+ end
218
+
219
+ end
220
+
221
+ end
222
+ end