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,185 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Rspec::Core::SharedBehaviour do
4
+
5
+ it "should add the 'share_examples_for' method to the global namespace" do
6
+ Kernel.should respond_to(:share_examples_for)
7
+ end
8
+
9
+ it "should add the 'shared_examples_for' method to the global namespace" do
10
+ Kernel.should respond_to(:shared_examples_for)
11
+ end
12
+
13
+ it "should add the 'share_as' method to the global namespace" do
14
+ Kernel.should respond_to(:share_as)
15
+ end
16
+
17
+ it "should raise an ArgumentError when adding a second shared behaviour with the same name" do
18
+ group = double_describe('example group')
19
+ group.share_examples_for('really important business value') { }
20
+ lambda do
21
+ group.share_examples_for('really important business value') { }
22
+ end.should raise_error(ArgumentError, "Shared example group 'really important business value' already exists")
23
+ end
24
+
25
+ describe "share_examples_for" do
26
+
27
+ it "should capture the given name and block in the Worlds collection of shared behaviours" do
28
+ Rspec::Core.world.shared_behaviours.expects(:[]=).with(:foo, anything)
29
+ share_examples_for(:foo) { }
30
+ end
31
+
32
+ end
33
+
34
+ describe "including shared behaviours using #it_should_behave_like" do
35
+
36
+ def cleanup_shared_behaviours
37
+ original_shared_behaviours = Rspec::Core.world.shared_behaviours
38
+ yield if block_given?
39
+ Rspec::Core.world.shared_behaviours.replace(original_shared_behaviours)
40
+ end
41
+
42
+ it "should module_eval any found shared behaviours" do
43
+ group = double_describe('fake group')
44
+ block1 = lambda {}
45
+ block2 = lambda {
46
+ def extra_helper
47
+ 'extra_helper'
48
+ end
49
+ }
50
+ Rspec::Core.world.stubs(:shared_behaviours).returns({ :a => block1, :shared_behaviour => block2 })
51
+ group.expects(:module_eval).once
52
+ group.it_should_behave_like :shared_behaviour
53
+ end
54
+
55
+ it "should make any shared behaviour available at the correct level" do
56
+ group = double_describe('fake group')
57
+ block = lambda {
58
+ def self.class_helper; end
59
+ def extra_helper; end
60
+ }
61
+ Rspec::Core.world.stubs(:shared_behaviours).returns({ :shared_behaviour => block })
62
+ group.it_should_behave_like :shared_behaviour
63
+ with_ruby(1.8) do
64
+ group.instance_methods.should include('extra_helper')
65
+ group.singleton_methods.should include('class_helper')
66
+ end
67
+ with_ruby(1.9) do
68
+ group.instance_methods.should include(:extra_helper)
69
+ group.singleton_methods.should include(:class_helper)
70
+ end
71
+ end
72
+
73
+ it "should raise when named shared example_group can not be found"
74
+
75
+ it "adds examples to current example_group using it_should_behave_like" do
76
+ cleanup_shared_behaviours do
77
+ group = double_describe("example_group") do |g|
78
+ g.it("i was already here") {}
79
+ end
80
+
81
+ group.examples.size.should == 1
82
+
83
+ group.share_examples_for('shared example_group') do
84
+ it("shared example") {}
85
+ it("shared example 2") {}
86
+ end
87
+
88
+ group.it_should_behave_like("shared example_group")
89
+
90
+ group.examples.size.should == 3
91
+ end
92
+ end
93
+
94
+ it "adds examples to from two shared groups" do
95
+ cleanup_shared_behaviours do
96
+ group = double_describe("example_group") do |g|
97
+ g.it("i was already here") {}
98
+ end
99
+
100
+ group.examples.size.should == 1
101
+
102
+ group.share_examples_for('test 2 shared groups') do
103
+ it("shared example") {}
104
+ it("shared example 2") {}
105
+ end
106
+
107
+ group.share_examples_for('test 2 shared groups 2') do
108
+ it("shared example 3") {}
109
+ end
110
+
111
+ group.it_should_behave_like("test 2 shared groups")
112
+ group.it_should_behave_like("test 2 shared groups 2")
113
+
114
+ group.examples.size.should == 4
115
+ end
116
+ end
117
+
118
+ share_as('Cornucopia') do
119
+ it "should do foo"
120
+ end
121
+
122
+ it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
123
+ group = double_describe('group') { include Cornucopia }
124
+ group.should have(1).example
125
+ end
126
+
127
+ it "adds examples to current example_group using it_should_behave_like with a module" do
128
+ cleanup_shared_behaviours do
129
+ group = double_describe("example_group") {}
130
+
131
+ shared_foo = group.share_as(:FooShared) do
132
+ it("shared example") {}
133
+ end
134
+
135
+ group.it_should_behave_like(::FooShared)
136
+
137
+ group.examples.size.should == 1
138
+ end
139
+ end
140
+
141
+ describe "running shared examples" do
142
+ module RunningSharedExamplesJustForTesting; end
143
+
144
+ share_examples_for("it runs shared examples") do
145
+ include RunningSharedExamplesJustForTesting
146
+
147
+ def magic
148
+ @magic ||= {}
149
+ end
150
+
151
+ before(:each) { magic[:before_each] = 'each' }
152
+ after(:each) { magic[:after_each] = 'each' }
153
+ before(:all) { magic[:before_all] = 'all' }
154
+ end
155
+
156
+ it_should_behave_like "it runs shared examples"
157
+
158
+ it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
159
+ magic[:before_each].should == 'each'
160
+ end
161
+
162
+ it "runs after(:each) from shared example_group", :compat => 'rspec-1.2'
163
+
164
+ it "should run before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
165
+ magic[:before_all].should == 'all'
166
+ end
167
+
168
+ it "should run after(:all) only once from shared example_group", :compat => 'rspec-1.2'
169
+
170
+ it "should include modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
171
+ running_example.behaviour.included_modules.should include(RunningSharedExamplesJustForTesting)
172
+ end
173
+
174
+ it "should make methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
175
+ # TODO: Consider should have_method(...) simple matcher
176
+ with_ruby('1.8') { running_example.behaviour.methods.should include('magic') }
177
+ with_ruby('1.9') { running_example.behaviour.methods.should include(:magic) }
178
+ end
179
+
180
+ end
181
+
182
+ end
183
+
184
+
185
+ end
@@ -0,0 +1,167 @@
1
+ require 'spec/spec_helper'
2
+
3
+ class Bar; end
4
+ class Foo; end
5
+
6
+ describe Rspec::Core::World do
7
+
8
+ before do
9
+ @world = Rspec::Core::World.new
10
+ Rspec::Core.stubs(:world).returns(@world)
11
+ end
12
+
13
+ describe "behaviour groups" do
14
+
15
+ it "should contain all defined behaviour groups" do
16
+ behaviour_group = Rspec::Core::ExampleGroup.describe(Bar, 'Empty Behaviour Group') { }
17
+ @world.behaviours.should include(behaviour_group)
18
+ end
19
+
20
+ end
21
+
22
+ describe "applying inclusion filters" do
23
+
24
+ before(:all) do
25
+ options_1 = { :foo => 1, :color => 'blue', :feature => 'reporting' }
26
+ options_2 = { :pending => true, :feature => 'reporting' }
27
+ options_3 = { :array => [1,2,3,4], :color => 'blue', :feature => 'weather status' }
28
+ @bg1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options_1) { }
29
+ @bg2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-2", options_2) { }
30
+ @bg3 = Rspec::Core::ExampleGroup.describe(Bar, "find group-3", options_3) { }
31
+ @bg4 = Rspec::Core::ExampleGroup.describe(Foo, "find these examples") do
32
+ it('I have no options') {}
33
+ it("this is awesome", :awesome => true) {}
34
+ it("this is too", :awesome => true) {}
35
+ it("not so awesome", :awesome => false) {}
36
+ it("I also have no options") {}
37
+ end
38
+ @behaviours = [@bg1, @bg2, @bg3, @bg4]
39
+ end
40
+
41
+ after(:all) do
42
+ Rspec::Core.world.behaviours.delete(@bg1)
43
+ Rspec::Core.world.behaviours.delete(@bg2)
44
+ Rspec::Core.world.behaviours.delete(@bg3)
45
+ Rspec::Core.world.behaviours.delete(@bg4)
46
+ end
47
+
48
+ it "should find awesome examples" do
49
+ @world.apply_inclusion_filters(@bg4.examples, :awesome => true).should == [@bg4.examples[1], @bg4.examples[2]]
50
+ end
51
+
52
+ it "should find no groups when given no search parameters" do
53
+ @world.apply_inclusion_filters([]).should == []
54
+ end
55
+
56
+ it "should find three groups when searching for :behaviour_describes => Bar" do
57
+ @world.apply_inclusion_filters(@behaviours, :behaviour => { :describes => Bar }).should == [@bg1, @bg2, @bg3]
58
+ end
59
+
60
+ it "should find one group when searching for :description => 'find group-1'" do
61
+ @world.apply_inclusion_filters(@behaviours, :behaviour => { :description => 'find group-1' }).should == [@bg1]
62
+ end
63
+
64
+ it "should find two groups when searching for :description => lambda { |v| v.include?('-1') || v.include?('-3') }" do
65
+ @world.apply_inclusion_filters(@behaviours, :behaviour => { :description => lambda { |v| v.include?('-1') || v.include?('-3') } }).should == [@bg1, @bg3]
66
+ end
67
+
68
+ it "should find three groups when searching for :description => /find group/" do
69
+ @world.apply_inclusion_filters(@behaviours, :behaviour => { :description => /find group/ }).should == [@bg1, @bg2, @bg3]
70
+ end
71
+
72
+ it "should find one group when searching for :foo => 1" do
73
+ @world.apply_inclusion_filters(@behaviours, :foo => 1 ).should == [@bg1]
74
+ end
75
+
76
+ it "should find one group when searching for :pending => true" do
77
+ @world.apply_inclusion_filters(@behaviours, :pending => true ).should == [@bg2]
78
+ end
79
+
80
+ it "should find one group when searching for :array => [1,2,3,4]" do
81
+ @world.apply_inclusion_filters(@behaviours, :array => [1,2,3,4]).should == [@bg3]
82
+ end
83
+
84
+ it "should find no group when searching for :array => [4,3,2,1]" do
85
+ @world.apply_inclusion_filters(@behaviours, :array => [4,3,2,1]).should be_empty
86
+ end
87
+
88
+ it "should find two groups when searching for :color => 'blue'" do
89
+ @world.apply_inclusion_filters(@behaviours, :color => 'blue').should == [@bg1, @bg3]
90
+ end
91
+
92
+ it "should find two groups when searching for :feature => 'reporting' }" do
93
+ @world.apply_inclusion_filters(@behaviours, :feature => 'reporting').should == [@bg1, @bg2]
94
+ end
95
+
96
+ end
97
+
98
+ describe "applying exclusion filters" do
99
+
100
+ it "should find nothing if all describes match the exclusion filter" do
101
+ options = { :network_access => true }
102
+
103
+ isolate_behaviour do
104
+ group1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options) do
105
+ it("foo") {}
106
+ it("bar") {}
107
+ end
108
+
109
+ @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
110
+ end
111
+
112
+ isolate_behaviour do
113
+ group2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1") do
114
+ it("foo", :network_access => true) {}
115
+ it("bar") {}
116
+ end
117
+
118
+ @world.apply_exclusion_filters(group2.examples, :network_access => true).should == [group2.examples.last]
119
+ end
120
+
121
+ end
122
+
123
+ it "should find nothing if a regexp matches the exclusion filter" do
124
+ isolate_behaviour do
125
+ group = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
126
+ it("foo") {}
127
+ it("bar") {}
128
+ end
129
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/).should == []
130
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo").should == []
131
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, :another => "foo", :behaviour => {
132
+ :describes => lambda { |b| b == Bar } } ).should == []
133
+
134
+ @world.apply_exclusion_filters(group.examples, :name => /exclude not/).should == group.examples
135
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo").should == group.examples
136
+ @world.apply_exclusion_filters(group.examples, :name => /exclude/, "another_condition" => "foo1").should == group.examples
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ describe "filtering behaviours" do
143
+
144
+ before(:all) do
145
+ @group1 = Rspec::Core::ExampleGroup.describe(Bar, "find these examples") do
146
+ it('I have no options', :color => :red, :awesome => true) {}
147
+ it("I also have no options", :color => :red, :awesome => true) {}
148
+ it("not so awesome", :color => :red, :awesome => false) {}
149
+ end
150
+ end
151
+
152
+ after(:all) do
153
+ Rspec::Core.world.behaviours.delete(@group1)
154
+ end
155
+
156
+ it "should run matches" do
157
+ Rspec::Core.world.stubs(:exclusion_filter).returns({ :awesome => false })
158
+ Rspec::Core.world.stubs(:filter).returns({ :color => :red })
159
+ Rspec::Core.world.stubs(:behaviours).returns([@group1])
160
+ filtered_behaviours = @world.filter_behaviours
161
+ filtered_behaviours.should == [@group1]
162
+ @group1.examples_to_run.should == @group1.examples[0..1]
163
+ end
164
+
165
+ end
166
+
167
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Rspec::Core do
4
+
5
+ describe "#configuration" do
6
+
7
+ it "should return an instance of Rspec::Core::Configuration" do
8
+ Rspec::Core.configuration.should be_an_instance_of(Rspec::Core::Configuration)
9
+ end
10
+
11
+ end
12
+
13
+ describe "#configure" do
14
+
15
+ it "should yield the current configuration" do
16
+ Rspec::Core.configure do |config|
17
+ config.should == Rspec::Core.configuration
18
+ end
19
+ end
20
+
21
+ it "should be callable without a block" do
22
+ lambda { Rspec::Core.configure }.should_not raise_error
23
+ end
24
+
25
+ end
26
+
27
+ describe "#world" do
28
+
29
+ it "should return the Rspec::Core::World instance the current run is using" do
30
+ Rspec::Core.world.should be_instance_of(Rspec::Core::World)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,13 @@
1
+ require 'rbconfig'
2
+
3
+ module RubyForker
4
+ # Forks a ruby interpreter with same type as ourself.
5
+ # juby will fork jruby, ruby will fork ruby etc.
6
+ def ruby(args, stderr=nil)
7
+ config = ::Config::CONFIG
8
+ interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
9
+ cmd = "#{interpreter} #{args}"
10
+ cmd << " 2> #{stderr}" unless stderr.nil?
11
+ `#{cmd}`
12
+ end
13
+ end
@@ -0,0 +1,72 @@
1
+ dir = File.dirname(__FILE__)
2
+ lib_path = File.expand_path("#{dir}/../lib")
3
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
4
+
5
+ require 'rubygems'
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../expectations/lib'))
7
+ require 'rspec/expectations'
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../mocks/lib'))
9
+ require 'rspec/mocks'
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ require 'rspec/core'
12
+
13
+ Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
14
+
15
+ def with_ruby(version)
16
+ yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
17
+ end
18
+
19
+ require 'rubygems'
20
+ require 'mocha'
21
+
22
+ require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
23
+
24
+ module Rspec
25
+ module Core
26
+ module Matchers
27
+ def fail
28
+ raise_error(::Rspec::Expectations::ExpectationNotMetError)
29
+ end
30
+
31
+ def fail_with(message)
32
+ raise_error(::Rspec::Expectations::ExpectationNotMetError, message)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def remove_last_describe_from_world
39
+ Rspec::Core.world.behaviours.pop
40
+ end
41
+
42
+ def isolate_behaviour
43
+ if block_given?
44
+ yield
45
+ Rspec::Core.world.behaviours.pop
46
+ end
47
+ end
48
+
49
+ def double_describe(*args)
50
+ group = Rspec::Core::ExampleGroup.describe(*args) {}
51
+ remove_last_describe_from_world
52
+ yield group if block_given?
53
+ group
54
+ end
55
+
56
+ def use_formatter(new_formatter)
57
+ original_formatter = Rspec::Core.configuration.formatter
58
+ Rspec::Core.configuration.instance_variable_set(:@formatter, new_formatter)
59
+ yield
60
+ ensure
61
+ Rspec::Core.configuration.instance_variable_set(:@formatter, original_formatter)
62
+ end
63
+
64
+ def not_in_editor?
65
+ !(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM'))
66
+ end
67
+
68
+ Rspec::Core.configure do |c|
69
+ c.mock_framework = :mocha
70
+ c.filter_run :focused => true
71
+ c.color_enabled = not_in_editor?
72
+ end