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,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "irb"
3
+ lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib")
4
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
5
+
6
+ require 'rspec/core'
7
+
8
+ IRB.start(__FILE__)
@@ -0,0 +1,67 @@
1
+ # This file contains various classes used by the specs.
2
+ module Rspec::Core
3
+ module Expectations
4
+ class Person
5
+ attr_reader :name
6
+ def initialize name
7
+ @name = name
8
+ end
9
+ def == other
10
+ return @name == other.name
11
+ end
12
+ end
13
+
14
+ class ClassWithMultiWordPredicate
15
+ def multi_word_predicate?
16
+ true
17
+ end
18
+ end
19
+
20
+ module Helper
21
+ class CollectionWithSizeMethod
22
+ def initialize; @list = []; end
23
+ def size; @list.size; end
24
+ def push(item); @list.push(item); end
25
+ end
26
+
27
+ class CollectionWithLengthMethod
28
+ def initialize; @list = []; end
29
+ def length; @list.size; end
30
+ def push(item); @list.push(item); end
31
+ end
32
+
33
+ class CollectionOwner
34
+ attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method
35
+
36
+ def initialize
37
+ @items_in_collection_with_size_method = CollectionWithSizeMethod.new
38
+ @items_in_collection_with_length_method = CollectionWithLengthMethod.new
39
+ end
40
+
41
+ def add_to_collection_with_size_method(item)
42
+ @items_in_collection_with_size_method.push(item)
43
+ end
44
+
45
+ def add_to_collection_with_length_method(item)
46
+ @items_in_collection_with_length_method.push(item)
47
+ end
48
+
49
+ def items_for(arg)
50
+ return [1, 2, 3] if arg == 'a'
51
+ [1]
52
+ end
53
+
54
+ def items
55
+ @items_in_collection_with_size_method
56
+ end
57
+ end
58
+
59
+ class ClassWithUnqueriedPredicate
60
+ attr_accessor :foo
61
+ def initialize(foo)
62
+ @foo = foo
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Rspec::Core::CommandLineOptions do
4
+
5
+ def options_from_args(*args)
6
+ Rspec::Core::CommandLineOptions.new(args).parse
7
+ end
8
+
9
+ describe 'color_enabled' do
10
+
11
+ example "-c, --colour, or --color should be parsed as true" do
12
+ options_from_args('-c').should include(:color_enabled => true)
13
+ options_from_args('--color').should include(:color_enabled => true)
14
+ options_from_args('--colour').should include(:color_enabled => true)
15
+ end
16
+
17
+ example "--no-color should be parsed as false" do
18
+ options_from_args('--no-color').should include(:color_enabled => false)
19
+ end
20
+
21
+ end
22
+
23
+ describe 'formatter' do
24
+
25
+ example '-f or --formatter with no arguments should be parsed as nil' do
26
+ options_from_args('--formatter').should include(:formatter => nil)
27
+ end
28
+
29
+ example '-f or --formatter with an argument should parse' do
30
+ options_from_args('--formatter', 'd').should include(:formatter => 'd')
31
+ options_from_args('-f', 'd').should include(:formatter => 'd')
32
+ options_from_args('-fd').should include(:formatter => 'd')
33
+ end
34
+
35
+ end
36
+
37
+ describe 'profile_examples' do
38
+
39
+ example "-p or --profile should be parsed as true" do
40
+ options_from_args('-p').should include(:profile_examples => true)
41
+ options_from_args('--profile').should include(:profile_examples => true)
42
+ end
43
+
44
+ end
45
+
46
+ describe 'files_to_run' do
47
+
48
+ example '-c file.rb dir/file.rb should parse' do
49
+ options_from_args('-c', 'file.rb', 'dir/file.rb').should include(:files_to_run => ['file.rb', 'dir/file.rb'])
50
+ end
51
+
52
+ example 'dir should parse' do
53
+ options_from_args('dir').should include(:files_to_run => ['dir'])
54
+ end
55
+
56
+ example 'spec/file1_spec.rb, spec/file2_spec.rb should parse' do
57
+ options_from_args('spec/file1_spec.rb', 'spec/file2_spec.rb').should include(:files_to_run => ['spec/file1_spec.rb', 'spec/file2_spec.rb'])
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,171 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Rspec::Core::Configuration do
4
+
5
+ describe "setting the mock framework" do
6
+
7
+ # TODO: Solution to test rr/rspec/flexmock, possibly cucumber
8
+ it "requires and includes the mocha adapter when the mock_framework is :mocha" do
9
+ config = Rspec::Core::Configuration.new
10
+ config.expects(:require).with('rspec/core/mocking/with_mocha')
11
+ Rspec::Core::ExampleGroup.expects(:send)
12
+ config.mock_framework = :mocha
13
+ end
14
+
15
+ it "supports mock_with for backward compatibility with rspec-1.x" do
16
+ config = Rspec::Core::Configuration.new
17
+ config.expects(:require).with('rspec/core/mocking/with_mocha')
18
+ Rspec::Core::ExampleGroup.expects(:send)
19
+ config.mock_with :mocha
20
+ end
21
+
22
+ it "includes the null adapter when the mock_framework is not :rspec, :mocha, or :rr" do
23
+ config = Rspec::Core::Configuration.new
24
+ Rspec::Core::ExampleGroup.expects(:send).with(:include, Rspec::Core::Mocking::WithAbsolutelyNothing)
25
+ config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
26
+ end
27
+
28
+ end
29
+
30
+ describe "setting the files to run" do
31
+
32
+ before do
33
+ @config = Rspec::Core::Configuration.new
34
+ end
35
+
36
+ it "should load files not following pattern if named explicitly" do
37
+ file = File.expand_path(File.dirname(__FILE__) + "/resources/a_bar.rb")
38
+ @config.files_to_run = file
39
+ @config.files_to_run.should include(file)
40
+ end
41
+
42
+ describe "with default --pattern" do
43
+
44
+ it "should load files named _spec.rb" do
45
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources/")
46
+ @config.files_to_run = dir
47
+ @config.files_to_run.should == ["#{dir}/a_spec.rb"]
48
+ end
49
+
50
+ end
51
+
52
+ describe "with explicit pattern (single)" do
53
+
54
+ before do
55
+ @config.filename_pattern = "**/*_foo.rb"
56
+ end
57
+
58
+ it "should load files following pattern" do
59
+ file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
60
+ @config.files_to_run = file
61
+ @config.files_to_run.should include(file)
62
+ end
63
+
64
+ it "should load files in directories following pattern" do
65
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
66
+ @config.files_to_run = dir
67
+ @config.files_to_run.should include("#{dir}/a_foo.rb")
68
+ end
69
+
70
+ it "should not load files in directories not following pattern" do
71
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
72
+ @config.files_to_run = dir
73
+ @config.files_to_run.should_not include("#{dir}/a_bar.rb")
74
+ end
75
+
76
+ end
77
+
78
+ describe "with explicit pattern (comma,separated,values)" do
79
+
80
+ before do
81
+ @config.filename_pattern = "**/*_foo.rb,**/*_bar.rb"
82
+ end
83
+
84
+ it "should support comma separated values" do
85
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
86
+ @config.files_to_run = dir
87
+ @config.files_to_run.should include("#{dir}/a_foo.rb")
88
+ @config.files_to_run.should include("#{dir}/a_bar.rb")
89
+ end
90
+
91
+ it "should support comma separated values with spaces" do
92
+ dir = File.expand_path(File.dirname(__FILE__) + "/resources")
93
+ @config.files_to_run = dir
94
+ @config.files_to_run.should include("#{dir}/a_foo.rb")
95
+ @config.files_to_run.should include("#{dir}/a_bar.rb")
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
102
+ describe "include" do
103
+
104
+ module InstanceLevelMethods
105
+ def you_call_this_a_blt?
106
+ "egad man, where's the mayo?!?!?"
107
+ end
108
+ end
109
+
110
+ it "should include the given module into each matching behaviour" do
111
+ Rspec::Core.configuration.include(InstanceLevelMethods, :magic_key => :include)
112
+
113
+ isolate_behaviour do
114
+ group = Rspec::Core::ExampleGroup.describe(Object, 'does like, stuff and junk', :magic_key => :include) { }
115
+ group.should_not respond_to(:you_call_this_a_blt?)
116
+ group.new.you_call_this_a_blt?.should == "egad man, where's the mayo?!?!?"
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ describe "extend" do
123
+
124
+ module ThatThingISentYou
125
+
126
+ def that_thing
127
+ end
128
+
129
+ end
130
+
131
+ it "should extend the given module into each matching behaviour" do
132
+ Rspec::Core.configuration.extend(ThatThingISentYou, :magic_key => :extend)
133
+ group = Rspec::Core::ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
134
+
135
+ group.should respond_to(:that_thing)
136
+ remove_last_describe_from_world
137
+ end
138
+
139
+ end
140
+
141
+ describe "run_all_when_everything_filtered" do
142
+
143
+ it "defaults to true" do
144
+ Rspec::Core::Configuration.new.run_all_when_everything_filtered.should == true
145
+ end
146
+
147
+ it "can be queried with question method" do
148
+ config = Rspec::Core::Configuration.new
149
+ config.run_all_when_everything_filtered = false
150
+ config.run_all_when_everything_filtered?.should == false
151
+ end
152
+ end
153
+
154
+ describe 'formatter' do
155
+
156
+ it "sets formatter_to_use based on name" do
157
+ config = Rspec::Core::Configuration.new
158
+ config.formatter = :documentation
159
+ config.formatter.should be_an_instance_of(Rspec::Core::Formatters::DocumentationFormatter)
160
+ config.formatter = 'documentation'
161
+ config.formatter.should be_an_instance_of(Rspec::Core::Formatters::DocumentationFormatter)
162
+ end
163
+
164
+ it "raises ArgumentError if formatter is unknown" do
165
+ config = Rspec::Core::Configuration.new
166
+ lambda { config.formatter = :progresss }.should raise_error(ArgumentError)
167
+ end
168
+
169
+ end
170
+
171
+ end
@@ -0,0 +1,351 @@
1
+ require 'spec/spec_helper'
2
+
3
+ def empty_behaviour_group(name='Empty ExampleGroup Group')
4
+ group = Rspec::Core::ExampleGroup.describe(Object, name) {}
5
+ remove_last_describe_from_world
6
+ yield group if block_given?
7
+ group
8
+ end
9
+
10
+ describe Rspec::Core::ExampleGroup do
11
+
12
+ describe "describing behaviour with #describe" do
13
+
14
+ example "an ArgumentError is raised if no type or description is given" do
15
+ lambda { Rspec::Core::ExampleGroup.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
16
+ end
17
+
18
+ example "an ArgumentError is raised if no block is given" do
19
+ lambda { Rspec::Core::ExampleGroup.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
20
+ end
21
+
22
+ describe '#name' do
23
+
24
+ it "should expose the first parameter as name" do
25
+ isolate_behaviour do
26
+ Rspec::Core::ExampleGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
+ end
28
+ end
29
+
30
+ it "should call to_s on the first parameter in case it is a constant" do
31
+ isolate_behaviour do
32
+ Rspec::Core::ExampleGroup.describe(Object) { }.name.should == 'Object'
33
+ end
34
+ end
35
+
36
+ it "should be built correctly when nested" do
37
+ behaviour_to_test = nil
38
+ group = empty_behaviour_group('test')
39
+ group.name.should == 'Object test'
40
+
41
+ nested_group_one = group.describe('nested one') { }
42
+ nested_group_one.name.should == 'Object test nested one'
43
+
44
+ nested_group_two = nested_group_one.describe('nested two') { }
45
+ nested_group_two.name.should == 'Object test nested one nested two'
46
+ end
47
+
48
+ end
49
+
50
+ describe '#describes' do
51
+
52
+ it "should be the first parameter when it is a constant" do
53
+ isolate_behaviour do
54
+ Rspec::Core::ExampleGroup.describe(Object) { }.describes.should == Object
55
+ end
56
+ end
57
+
58
+ it "should be nil when the first parameter is a string" do
59
+ isolate_behaviour do
60
+ Rspec::Core::ExampleGroup.describe("i'm a computer") { }.describes.should be_nil
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ describe '#description' do
67
+
68
+ it "should expose the second parameter as description" do
69
+ isolate_behaviour do
70
+ Rspec::Core::ExampleGroup.describe(Object, "my desc") { }.description.should == 'my desc'
71
+ end
72
+ end
73
+
74
+ it "should allow the second parameter to be nil" do
75
+ isolate_behaviour do
76
+ Rspec::Core::ExampleGroup.describe(Object, nil) { }.description.size.should == 0
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ describe '#metadata' do
83
+
84
+ it "should add the third parameter to the metadata" do
85
+ isolate_behaviour do
86
+ Rspec::Core::ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
87
+ end
88
+ end
89
+
90
+ it "should add the caller to metadata" do
91
+ isolate_behaviour do
92
+ Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/
93
+ end
94
+ end
95
+
96
+ it "should add the the file_path to metadata" do
97
+ isolate_behaviour do
98
+ Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
99
+ end
100
+ end
101
+
102
+ it "should have a reader for file_path" do
103
+ isolate_behaviour do
104
+ Rspec::Core::ExampleGroup.describe(Object) { }.file_path.should == __FILE__
105
+ end
106
+ end
107
+
108
+ it "should add the line_number to metadata" do
109
+ isolate_behaviour do
110
+ Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
111
+ end
112
+ end
113
+
114
+ it "should add file path and line number metadata for arbitrarily nested describes" do
115
+ Rspec::Core::ExampleGroup.describe(Object) do
116
+ Rspec::Core::ExampleGroup.describe("foo") do
117
+ Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
118
+ Rspec::Core::ExampleGroup.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
119
+ end
120
+ end
121
+
122
+ 4.times { remove_last_describe_from_world }
123
+ end
124
+
125
+ end
126
+
127
+ describe "adding before and after hooks" do
128
+
129
+ it "should expose the before each blocks at before_eachs" do
130
+ group = empty_behaviour_group
131
+ group.before(:each) { 'foo' }
132
+ group.should have(1).before_eachs
133
+ end
134
+
135
+ it "should maintain the before each block order" do
136
+ group = empty_behaviour_group
137
+ group.before(:each) { 15 }
138
+ group.before(:each) { 'A' }
139
+ group.before(:each) { 33.5 }
140
+
141
+ group.before_eachs[0].call.should == 15
142
+ group.before_eachs[1].call.should == 'A'
143
+ group.before_eachs[2].call.should == 33.5
144
+ end
145
+
146
+ it "should expose the before all blocks at before_alls" do
147
+ group = empty_behaviour_group
148
+ group.before(:all) { 'foo' }
149
+ group.should have(1).before_alls
150
+ end
151
+
152
+ it "should maintain the before all block order" do
153
+ group = empty_behaviour_group
154
+ group.before(:all) { 15 }
155
+ group.before(:all) { 'A' }
156
+ group.before(:all) { 33.5 }
157
+
158
+ group.before_alls[0].call.should == 15
159
+ group.before_alls[1].call.should == 'A'
160
+ group.before_alls[2].call.should == 33.5
161
+ end
162
+
163
+ it "should expose the after each blocks at after_eachs" do
164
+ group = empty_behaviour_group
165
+ group.after(:each) { 'foo' }
166
+ group.should have(1).after_eachs
167
+ end
168
+
169
+ it "should maintain the after each block order" do
170
+ group = empty_behaviour_group
171
+ group.after(:each) { 15 }
172
+ group.after(:each) { 'A' }
173
+ group.after(:each) { 33.5 }
174
+
175
+ group.after_eachs[0].call.should == 15
176
+ group.after_eachs[1].call.should == 'A'
177
+ group.after_eachs[2].call.should == 33.5
178
+ end
179
+
180
+ it "should expose the after all blocks at after_alls" do
181
+ group = empty_behaviour_group
182
+ group.after(:all) { 'foo' }
183
+ group.should have(1).after_alls
184
+ end
185
+
186
+ it "should maintain the after each block order" do
187
+ group = empty_behaviour_group
188
+ group.after(:all) { 15 }
189
+ group.after(:all) { 'A' }
190
+ group.after(:all) { 33.5 }
191
+
192
+ group.after_alls[0].call.should == 15
193
+ group.after_alls[1].call.should == 'A'
194
+ group.after_alls[2].call.should == 33.5
195
+ end
196
+
197
+ end
198
+
199
+ describe "adding examples" do
200
+
201
+ it "should allow adding an example using 'it'" do
202
+ group = empty_behaviour_group
203
+ group.it("should do something") { }
204
+ group.examples.size.should == 1
205
+ end
206
+
207
+ it "should expose all examples at examples" do
208
+ group = empty_behaviour_group
209
+ group.it("should do something 1") { }
210
+ group.it("should do something 2") { }
211
+ group.it("should do something 3") { }
212
+ group.examples.size.should == 3
213
+ end
214
+
215
+ it "should maintain the example order" do
216
+ group = empty_behaviour_group
217
+ group.it("should 1") { }
218
+ group.it("should 2") { }
219
+ group.it("should 3") { }
220
+ group.examples[0].description.should == 'should 1'
221
+ group.examples[1].description.should == 'should 2'
222
+ group.examples[2].description.should == 'should 3'
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ describe Object, "describing nested behaviours", :little_less_nested => 'yep' do
230
+
231
+ describe "A sample nested describe", :nested_describe => "yep" do
232
+
233
+ it "should set the described type to the constant Object" do
234
+ running_example.behaviour.describes.should == Object
235
+ end
236
+
237
+ it "should set the description to 'A sample nested describe'" do
238
+ running_example.behaviour.description.should == 'A sample nested describe'
239
+ end
240
+
241
+ it "should have top level metadata from the behaviour and its ancestors" do
242
+ running_example.behaviour.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
243
+ end
244
+
245
+ it "should make the parent metadata available on the contained examples" do
246
+ running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
247
+ end
248
+
249
+ end
250
+
251
+ end
252
+
253
+ describe "#run_examples" do
254
+
255
+ before do
256
+ @fake_formatter = Rspec::Core::Formatters::BaseFormatter.new
257
+ end
258
+
259
+ def stub_behaviour
260
+ stub_everything('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }})
261
+ end
262
+
263
+ it "should return true if all examples pass" do
264
+ use_formatter(@fake_formatter) do
265
+ passing_example1 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
266
+ passing_example2 = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
267
+ Rspec::Core::ExampleGroup.stubs(:examples_to_run).returns([passing_example1, passing_example2])
268
+
269
+ Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter')).should be_true
270
+ end
271
+ end
272
+
273
+ it "should return false if any of the examples return false" do
274
+ use_formatter(@fake_formatter) do
275
+ failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
276
+ passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
277
+ Rspec::Core::ExampleGroup.stubs(:examples_to_run).returns([failing_example, passing_example])
278
+
279
+ Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter')).should be_false
280
+ end
281
+ end
282
+
283
+ it "should run all examples, regardless of any of them failing" do
284
+ use_formatter(@fake_formatter) do
285
+ failing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
286
+ passing_example = Rspec::Core::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
287
+ Rspec::Core::ExampleGroup.stubs(:examples_to_run).returns([failing_example, passing_example])
288
+
289
+ passing_example.expects(:run)
290
+
291
+ Rspec::Core::ExampleGroup.run_examples(stub_behaviour, stub_everything('reporter'))
292
+ end
293
+ end
294
+
295
+ end
296
+
297
+ describe "how instance variables inherit" do
298
+
299
+ before(:all) do
300
+ @before_all_top_level = 'before_all_top_level'
301
+ end
302
+
303
+ before(:each) do
304
+ @before_each_top_level = 'before_each_top_level'
305
+ end
306
+
307
+ it "should be able to access a before each ivar at the same level" do
308
+ @before_each_top_level.should == 'before_each_top_level'
309
+ end
310
+
311
+ it "should be able to access a before all ivar at the same level" do
312
+ @before_all_top_level.should == 'before_all_top_level'
313
+ end
314
+
315
+
316
+ it "should be able to access the before all ivars in the before_all_ivars hash" do
317
+ with_ruby('1.8') do
318
+ running_example.behaviour.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
319
+ end
320
+ with_ruby('1.9') do
321
+ running_example.behaviour.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
322
+ end
323
+ end
324
+
325
+ describe "but now I am nested" do
326
+
327
+ it "should be able to access a parent behaviours before each ivar at a nested level" do
328
+ @before_each_top_level.should == 'before_each_top_level'
329
+ end
330
+
331
+ it "should be able to access a parent behaviours before all ivar at a nested level" do
332
+ @before_all_top_level.should == "before_all_top_level"
333
+ end
334
+
335
+ it "changes to before all ivars from within an example do not persist outside the current describe" do
336
+ @before_all_top_level = "ive been changed"
337
+ end
338
+
339
+ describe "accessing a before_all ivar that was changed in a parent behaviour" do
340
+
341
+ it "should have access to the modified version" do
342
+ @before_all_top_level.should == 'ive been changed'
343
+ end
344
+
345
+ end
346
+
347
+ end
348
+
349
+ end
350
+
351
+ end