rspec-core 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +12 -14
  3. data/README.md +4 -1
  4. data/Rakefile +29 -12
  5. data/cucumber.yml +1 -1
  6. data/features/.nav +15 -9
  7. data/features/Autotest.md +31 -7
  8. data/features/Changelog.md +46 -3
  9. data/features/Upgrade.md +35 -2
  10. data/features/command_line/README.md +22 -0
  11. data/features/command_line/configure.feature +2 -2
  12. data/features/command_line/example_name_option.feature +10 -10
  13. data/features/command_line/exit_status.feature +4 -4
  14. data/features/command_line/format_option.feature +4 -4
  15. data/features/command_line/line_number_appended_to_path.feature +11 -11
  16. data/features/command_line/line_number_option.feature +2 -2
  17. data/features/command_line/rake_task.feature +3 -3
  18. data/features/command_line/tag.feature +30 -14
  19. data/features/configuration/alias_example_to.feature +48 -0
  20. data/features/configuration/custom_settings.feature +3 -3
  21. data/features/configuration/fail_fast.feature +3 -3
  22. data/features/configuration/read_options_from_file.feature +4 -4
  23. data/features/example_groups/basic_structure.feature +11 -15
  24. data/features/example_groups/shared_context.feature +74 -0
  25. data/features/example_groups/shared_example_group.feature +21 -17
  26. data/features/expectation_framework_integration/configure_expectation_framework.feature +15 -4
  27. data/features/filtering/exclusion_filters.feature +28 -4
  28. data/features/filtering/{implicit_filters.feature → if_and_unless.feature} +9 -7
  29. data/features/filtering/inclusion_filters.feature +26 -3
  30. data/features/filtering/run_all_when_everything_filtered.feature +2 -2
  31. data/features/formatters/custom_formatter.feature +1 -1
  32. data/features/formatters/text_formatter.feature +43 -0
  33. data/features/helper_methods/arbitrary_methods.feature +2 -2
  34. data/features/helper_methods/let.feature +2 -2
  35. data/features/helper_methods/modules.feature +149 -0
  36. data/features/hooks/around_hooks.feature +18 -11
  37. data/features/hooks/before_and_after_hooks.feature +15 -19
  38. data/features/hooks/filtering.feature +160 -124
  39. data/features/metadata/current_example.feature +17 -0
  40. data/features/metadata/described_class.feature +2 -2
  41. data/features/metadata/user_defined.feature +111 -0
  42. data/features/mock_framework_integration/use_any_framework.feature +1 -1
  43. data/features/mock_framework_integration/use_flexmock.feature +83 -10
  44. data/features/mock_framework_integration/use_mocha.feature +84 -10
  45. data/features/mock_framework_integration/use_rr.feature +85 -10
  46. data/features/mock_framework_integration/use_rspec.feature +84 -10
  47. data/features/pending/pending_examples.feature +8 -8
  48. data/features/spec_files/arbitrary_file_suffix.feature +1 -1
  49. data/features/step_definitions/additional_cli_steps.rb +11 -1
  50. data/features/subject/attribute_of_subject.feature +24 -4
  51. data/features/subject/explicit_subject.feature +5 -5
  52. data/features/subject/implicit_receiver.feature +2 -2
  53. data/features/subject/implicit_subject.feature +2 -2
  54. data/features/support/env.rb +6 -1
  55. data/lib/rspec/core/backward_compatibility.rb +12 -2
  56. data/lib/rspec/core/command_line.rb +2 -5
  57. data/lib/rspec/core/configuration.rb +70 -38
  58. data/lib/rspec/core/configuration_options.rb +6 -23
  59. data/lib/rspec/core/drb_command_line.rb +5 -11
  60. data/lib/rspec/core/example.rb +29 -21
  61. data/lib/rspec/core/example_group.rb +40 -8
  62. data/lib/rspec/core/extensions/object.rb +0 -1
  63. data/lib/rspec/core/formatters/base_formatter.rb +6 -0
  64. data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
  65. data/lib/rspec/core/formatters/helpers.rb +0 -4
  66. data/lib/rspec/core/hooks.rb +14 -4
  67. data/lib/rspec/core/metadata.rb +1 -1
  68. data/lib/rspec/core/metadata_hash_builder.rb +93 -0
  69. data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
  70. data/lib/rspec/core/mocking/with_mocha.rb +2 -0
  71. data/lib/rspec/core/mocking/with_rr.rb +2 -0
  72. data/lib/rspec/core/mocking/with_rspec.rb +3 -1
  73. data/lib/rspec/core/option_parser.rb +9 -2
  74. data/lib/rspec/core/pending.rb +10 -3
  75. data/lib/rspec/core/reporter.rb +2 -2
  76. data/lib/rspec/core/runner.rb +38 -13
  77. data/lib/rspec/core/shared_example_group.rb +18 -4
  78. data/lib/rspec/core/subject.rb +4 -6
  79. data/lib/rspec/core/version.rb +1 -1
  80. data/lib/rspec/core/world.rb +70 -18
  81. data/lib/rspec/core.rb +29 -0
  82. data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
  83. data/rspec-core.gemspec +3 -5
  84. data/spec/autotest/failed_results_re_spec.rb +2 -2
  85. data/spec/rspec/core/command_line_spec.rb +36 -2
  86. data/spec/rspec/core/configuration_spec.rb +150 -70
  87. data/spec/rspec/core/deprecations_spec.rb +21 -0
  88. data/spec/rspec/core/drb_command_line_spec.rb +21 -56
  89. data/spec/rspec/core/example_group_spec.rb +213 -56
  90. data/spec/rspec/core/example_spec.rb +110 -0
  91. data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -2
  92. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +9 -0
  93. data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
  94. data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
  95. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +8 -10
  96. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
  97. data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
  98. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
  99. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -1
  100. data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +5 -5
  101. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +8 -10
  102. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +5 -5
  103. data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +5 -5
  104. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +5 -5
  105. data/spec/rspec/core/hooks_spec.rb +86 -0
  106. data/spec/rspec/core/metadata_spec.rb +7 -7
  107. data/spec/rspec/core/option_parser_spec.rb +26 -15
  108. data/spec/rspec/core/pending_example_spec.rb +12 -51
  109. data/spec/rspec/core/reporter_spec.rb +19 -3
  110. data/spec/rspec/core/resources/formatter_specs.rb +7 -1
  111. data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
  112. data/spec/rspec/core/runner_spec.rb +42 -10
  113. data/spec/rspec/core/shared_example_group_spec.rb +57 -21
  114. data/spec/rspec/core/subject_spec.rb +32 -11
  115. data/spec/rspec/core/world_spec.rb +147 -15
  116. data/spec/rspec/core_spec.rb +28 -0
  117. data/spec/spec_helper.rb +22 -2
  118. data/spec/support/matchers.rb +44 -13
  119. data/spec/support/shared_example_groups.rb +41 -0
  120. data/spec/support/spec_files.rb +44 -0
  121. data/spec.txt +1126 -0
  122. metadata +35 -16
  123. data/spec/ruby_forker.rb +0 -13
@@ -5,187 +5,223 @@ Feature: filters
5
5
  or example group, and used to make a hook only apply to examples with the
6
6
  given metadata.
7
7
 
8
+ If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
9
+ to `true`, you can specify metadata using only symbols.
10
+
8
11
  Scenario: filter `before(:each)` hooks using arbitrary metadata
9
12
  Given a file named "filter_before_each_hooks_spec.rb" with:
10
13
  """
11
14
  RSpec.configure do |config|
12
- config.before(:each, :foo => :bar) { puts "In hook" }
15
+ config.before(:each, :foo => :bar) do
16
+ invoked_hooks << :before_each_foo_bar
17
+ end
13
18
  end
14
19
 
15
- describe "group 1" do
16
- it("example 1") { }
17
- it("example 2", :foo => :bar) { }
18
- end
20
+ describe "a filtered before :each hook" do
21
+ let(:invoked_hooks) { [] }
19
22
 
20
- describe "group 2", :foo => :bar do
21
- it("example 1") { }
22
- it("example 2", :foo => :bar) { }
23
- end
24
- """
25
- When I run "rspec filter_before_each_hooks_spec.rb --format documentation"
26
- Then the output should contain:
27
- """
28
- group 1
29
- example 1
30
- In hook
31
- example 2
23
+ describe "group without matching metadata" do
24
+ it "does not run the hook" do
25
+ invoked_hooks.should be_empty
26
+ end
32
27
 
33
- group 2
34
- In hook
35
- example 1
36
- In hook
37
- example 2
28
+ it "runs the hook for an example with matching metadata", :foo => :bar do
29
+ invoked_hooks.should == [:before_each_foo_bar]
30
+ end
31
+ end
32
+
33
+ describe "group with matching metadata", :foo => :bar do
34
+ it "runs the hook" do
35
+ invoked_hooks.should == [:before_each_foo_bar]
36
+ end
37
+ end
38
+ end
38
39
  """
40
+ When I run `rspec filter_before_each_hooks_spec.rb`
41
+ Then the examples should all pass
39
42
 
40
43
  Scenario: filter `after(:each)` hooks using arbitrary metadata
41
44
  Given a file named "filter_after_each_hooks_spec.rb" with:
42
45
  """
43
46
  RSpec.configure do |config|
44
- config.after(:each, :foo => :bar) { puts "In hook" }
47
+ config.after(:each, :foo => :bar) do
48
+ raise "boom!"
49
+ end
45
50
  end
46
51
 
47
- describe "group 1" do
48
- it("example 1") { }
49
- it("example 2", :foo => :bar) { }
50
- end
52
+ describe "a filtered after :each hook" do
53
+ describe "group without matching metadata" do
54
+ it "does not run the hook" do
55
+ # should pass
56
+ end
51
57
 
52
- describe "group 2", :foo => :bar do
53
- it("example 1") { }
54
- it("example 2", :foo => :bar) { }
55
- end
56
- """
57
- When I run "rspec filter_after_each_hooks_spec.rb --format documentation"
58
- Then the output should contain:
59
- """
60
- group 1
61
- example 1
62
- In hook
63
- example 2
58
+ it "runs the hook for an example with matching metadata", :foo => :bar do
59
+ # should fail
60
+ end
61
+ end
64
62
 
65
- group 2
66
- In hook
67
- example 1
68
- In hook
69
- example 2
63
+ describe "group with matching metadata", :foo => :bar do
64
+ it "runs the hook" do
65
+ # should fail
66
+ end
67
+ end
68
+ end
70
69
  """
70
+ When I run `rspec filter_after_each_hooks_spec.rb`
71
+ Then the output should contain "3 examples, 2 failures"
71
72
 
72
73
  Scenario: filter around(:each) hooks using arbitrary metadata
73
74
  Given a file named "filter_around_each_hooks_spec.rb" with:
74
75
  """
75
76
  RSpec.configure do |config|
76
77
  config.around(:each, :foo => :bar) do |example|
77
- puts "Start hook"
78
+ order << :before_around_each_foo_bar
78
79
  example.run
79
- puts "End hook"
80
+ order.should == [:before_around_each_foo_bar, :example]
80
81
  end
81
82
  end
82
83
 
83
- describe "group 1" do
84
- it("example 1") { }
85
- it("example 2", :foo => :bar) { }
86
- end
84
+ describe "a filtered around(:each) hook" do
85
+ let(:order) { [] }
87
86
 
88
- describe "group 2", :foo => :bar do
89
- it("example 1") { }
90
- it("example 2", :foo => :bar) { }
91
- end
92
- """
93
- When I run "rspec filter_around_each_hooks_spec.rb --format documentation"
94
- Then the output should contain:
95
- """
96
- group 1
97
- example 1
98
- Start hook
99
- End hook
100
- example 2
87
+ describe "a group without matching metadata" do
88
+ it "does not run the hook" do
89
+ order.should be_empty
90
+ end
101
91
 
102
- group 2
103
- Start hook
104
- End hook
105
- example 1
106
- Start hook
107
- End hook
108
- example 2
92
+ it "runs the hook for an example with matching metadata", :foo => :bar do
93
+ order.should == [:before_around_each_foo_bar]
94
+ order << :example
95
+ end
96
+ end
97
+
98
+ describe "a group with matching metadata", :foo => :bar do
99
+ it "runs the hook for an example with matching metadata", :foo => :bar do
100
+ order.should == [:before_around_each_foo_bar]
101
+ order << :example
102
+ end
103
+ end
104
+ end
109
105
  """
106
+ When I run `rspec filter_around_each_hooks_spec.rb`
107
+ Then the examples should all pass
110
108
 
111
109
  Scenario: filter before(:all) hooks using arbitrary metadata
112
110
  Given a file named "filter_before_all_hooks_spec.rb" with:
113
111
  """
114
112
  RSpec.configure do |config|
115
- config.before(:all, :foo => :bar) { puts "In hook" }
116
- end
117
-
118
- describe "group 1" do
119
- it("example 1") { }
120
- it("example 2") { }
113
+ config.before(:all, :foo => :bar) { @hook = :before_all_foo_bar }
121
114
  end
122
115
 
123
- describe "group 2", :foo => :bar do
124
- it("example 1") { }
125
- it("example 2") { }
126
- end
116
+ describe "a filtered before(:all) hook" do
117
+ describe "a group without matching metadata" do
118
+ it "does not run the hook" do
119
+ @hook.should be_nil
120
+ end
127
121
 
128
- describe "group 3" do
129
- describe "subgroup 1", :foo => :bar do
130
- it("example 1") { }
122
+ describe "a nested subgroup with matching metadata", :foo => :bar do
123
+ it "runs the hook" do
124
+ @hook.should == :before_all_foo_bar
125
+ end
126
+ end
131
127
  end
132
- end
133
- """
134
- When I run "rspec filter_before_all_hooks_spec.rb --format documentation"
135
- Then the output should contain:
136
- """
137
- group 1
138
- example 1
139
- example 2
140
128
 
141
- group 2
142
- In hook
143
- example 1
144
- example 2
129
+ describe "a group with matching metadata", :foo => :bar do
130
+ it "runs the hook" do
131
+ @hook.should == :before_all_foo_bar
132
+ end
145
133
 
146
- group 3
147
- subgroup 1
148
- In hook
149
- example 1
134
+ describe "a nested subgroup" do
135
+ it "runs the hook" do
136
+ @hook.should == :before_all_foo_bar
137
+ end
138
+ end
139
+ end
140
+ end
150
141
  """
142
+ When I run `rspec filter_before_all_hooks_spec.rb`
143
+ Then the examples should all pass
151
144
 
152
145
  Scenario: filter after(:all) hooks using arbitrary metadata
153
146
  Given a file named "filter_after_all_hooks_spec.rb" with:
154
147
  """
148
+ example_msgs = []
149
+
155
150
  RSpec.configure do |config|
156
- config.after(:all, :foo => :bar) { puts "In hook" }
151
+ config.after(:all, :foo => :bar) do
152
+ puts "after :all"
153
+ end
157
154
  end
158
155
 
159
- describe "group 1" do
160
- it("example 1") { }
161
- it("example 2") { }
162
- end
156
+ describe "a filtered after(:all) hook" do
157
+ describe "a group without matching metadata" do
158
+ it "does not run the hook" do
159
+ puts "unfiltered"
160
+ end
161
+ end
163
162
 
164
- describe "group 2", :foo => :bar do
165
- it("example 1") { }
166
- it("example 2") { }
167
- end
163
+ describe "a group with matching metadata", :foo => :bar do
164
+ it "runs the hook" do
165
+ puts "filtered 1"
166
+ end
167
+ end
168
168
 
169
- describe "group 3" do
170
- describe "subgroup 1", :foo => :bar do
171
- it("example 1") { }
169
+ describe "another group without matching metadata" do
170
+ describe "a nested subgroup with matching metadata", :foo => :bar do
171
+ it "runs the hook" do
172
+ puts "filtered 2"
173
+ end
174
+ end
172
175
  end
173
176
  end
174
177
  """
175
- When I run "rspec filter_after_all_hooks_spec.rb --format documentation"
176
- Then the output should contain:
178
+ When I run `rspec filter_after_all_hooks_spec.rb`
179
+ Then the examples should all pass
180
+ And the output should contain:
181
+ """
182
+ unfiltered
183
+ .filtered 1
184
+ .after :all
185
+ filtered 2
186
+ .after :all
177
187
  """
178
- group 1
179
- example 1
180
- example 2
181
188
 
182
- group 2
183
- example 1
184
- example 2
185
- In hook
189
+ Scenario: Use symbols as metadata
190
+ Given a file named "less_verbose_metadata_filter.rb" with:
191
+ """
192
+ RSpec.configure do |c|
193
+ c.treat_symbols_as_metadata_keys_with_true_values = true
194
+ c.before(:each, :before_each) { puts "before each" }
195
+ c.after(:each, :after_each) { puts "after each" }
196
+ c.around(:each, :around_each) do |example|
197
+ puts "around each (before)"
198
+ example.run
199
+ puts "around each (after)"
200
+ end
201
+ c.before(:all, :before_all) { puts "before all" }
202
+ c.after(:all, :after_all) { puts "after all" }
203
+ end
186
204
 
187
- group 3
188
- subgroup 1
189
- example 1
190
- In hook
205
+ describe "group 1", :before_all, :after_all do
206
+ it("") { puts "example 1" }
207
+ it("", :before_each) { puts "example 2" }
208
+ it("", :after_each) { puts "example 3" }
209
+ it("", :around_each) { puts "example 4" }
210
+ end
191
211
  """
212
+ When I run `rspec less_verbose_metadata_filter.rb`
213
+ Then the examples should all pass
214
+ And the output should contain:
215
+ """
216
+ before all
217
+ example 1
218
+ .before each
219
+ example 2
220
+ .example 3
221
+ after each
222
+ .around each (before)
223
+ example 4
224
+ around each (after)
225
+ .after all
226
+ """
227
+
@@ -0,0 +1,17 @@
1
+ Feature: current example
2
+
3
+ You can reference the example object, and access its metadata, using
4
+ the `example` method within an example.
5
+
6
+ Scenario: access the example object from within an example
7
+ Given a file named "spec/example_spec.rb" with:
8
+ """
9
+ describe "an example" do
10
+ it "knows itself as example" do
11
+ example.description.should eq("knows itself as example")
12
+ end
13
+ end
14
+ """
15
+ When I run `rspec spec/example_spec.rb`
16
+ Then the example should pass
17
+
@@ -12,6 +12,6 @@ Feature: described class
12
12
  end
13
13
  end
14
14
  """
15
- When I run "rspec ./spec/example_spec.rb"
16
- Then the examples should all pass
15
+ When I run `rspec spec/example_spec.rb`
16
+ Then the example should pass
17
17
 
@@ -0,0 +1,111 @@
1
+ Feature: User-defined metadata
2
+
3
+ You can attach user-defined metadata to any example group or example.
4
+ Pass a hash as the last argument (before the block) to `describe`,
5
+ `context` or `it`. RSpec supports many configuration options that apply
6
+ only to certain examples or groups based on the metadata.
7
+
8
+ Metadata defined on an example group is available (and can be overridden)
9
+ by any sub-group or from any example in that group or a sub-group.
10
+
11
+ In addition, there is a configuration option (which will be the default
12
+ behavior in RSpec 3) that allows you to specify metadata using just
13
+ symbols:
14
+
15
+ RSpec.configure do |c|
16
+ c.treat_symbols_as_metadata_keys_with_true_values = true
17
+ end
18
+
19
+ Each symbol passed as an argument to `describe`, `context` or `it` will
20
+ be a key in the metadata hash, with a corresponding value of `true`.
21
+
22
+ Scenario: define group metadata using a hash
23
+ Given a file named "define_group_metadata_with_hash_spec.rb" with:
24
+ """
25
+ describe "a group with user-defined metadata", :foo => 17 do
26
+ it 'has access to the metadata in the example' do
27
+ example.metadata[:foo].should == 17
28
+ end
29
+
30
+ it 'does not have access to metadata defined on sub-groups' do
31
+ example.metadata.should_not include(:bar)
32
+ end
33
+
34
+ describe 'a sub-group with user-defined metadata', :bar => 12 do
35
+ it 'has access to the sub-group metadata' do
36
+ example.metadata[:foo].should == 17
37
+ end
38
+
39
+ it 'also has access to metadata defined on parent groups' do
40
+ example.metadata[:bar].should == 12
41
+ end
42
+ end
43
+ end
44
+ """
45
+ When I run `rspec define_group_metadata_with_hash_spec.rb`
46
+ Then the examples should all pass
47
+
48
+ Scenario: define example metadata using a hash
49
+ Given a file named "define_example_metadata_with_hash_spec.rb" with:
50
+ """
51
+ describe "a group with no user-defined metadata" do
52
+ it 'has an example with metadata', :foo => 17 do
53
+ example.metadata[:foo].should == 17
54
+ example.metadata.should_not include(:bar)
55
+ end
56
+
57
+ it 'has another example with metadata', :bar => 12, :bazz => 33 do
58
+ example.metadata[:bar].should == 12
59
+ example.metadata[:bazz].should == 33
60
+ example.metadata.should_not include(:foo)
61
+ end
62
+ end
63
+ """
64
+ When I run `rspec define_example_metadata_with_hash_spec.rb`
65
+ Then the examples should all pass
66
+
67
+ Scenario: override user-defined metadata
68
+ Given a file named "override_metadata_spec.rb" with:
69
+ """
70
+ describe "a group with user-defined metadata", :foo => 'bar' do
71
+ it 'can be overridden by an example', :foo => 'bazz' do
72
+ example.metadata[:foo].should == 'bazz'
73
+ end
74
+
75
+ describe "a sub-group with an override", :foo => 'goo' do
76
+ it 'can be overridden by a sub-group' do
77
+ example.metadata[:foo].should == 'goo'
78
+ end
79
+ end
80
+ end
81
+ """
82
+ When I run `rspec override_metadata_spec.rb`
83
+ Then the examples should all pass
84
+
85
+ Scenario: less verbose metadata
86
+ Given a file named "less_verbose_metadata_spec.rb" with:
87
+ """
88
+ RSpec.configure do |c|
89
+ c.treat_symbols_as_metadata_keys_with_true_values = true
90
+ end
91
+
92
+ describe "a group with simple metadata", :fast, :simple, :bug => 73 do
93
+ it 'has `:fast => true` metadata' do
94
+ example.metadata[:fast].should == true
95
+ end
96
+
97
+ it 'has `:simple => true` metadata' do
98
+ example.metadata[:simple].should == true
99
+ end
100
+
101
+ it 'can still use a hash for metadata' do
102
+ example.metadata[:bug].should == 73
103
+ end
104
+
105
+ it 'can define simple metadata on an example', :special do
106
+ example.metadata[:special].should == true
107
+ end
108
+ end
109
+ """
110
+ When I run `rspec less_verbose_metadata_spec.rb`
111
+ Then the examples should all pass
@@ -100,7 +100,7 @@ Feature: mock with an alternative framework
100
100
  end
101
101
  end
102
102
  """
103
- When I run "rspec example_spec.rb --format doc"
103
+ When I run `rspec example_spec.rb --format doc`
104
104
  Then the exit status should be 1
105
105
  And the output should contain "2 examples, 1 failure"
106
106
  And the output should contain "fails when message is received (FAILED - 1)"
@@ -1,23 +1,96 @@
1
1
  Feature: mock with flexmock
2
2
 
3
- As an RSpec user who likes to mock
4
- I want to be able to use flexmock
3
+ Configure RSpec to use flexmock as shown in the scenarios below.
5
4
 
6
- Scenario: Mock with flexmock
7
- Given a file named "flexmock_example_spec.rb" with:
5
+ Scenario: passing message expectation
6
+ Given a file named "example_spec.rb" with:
8
7
  """
9
8
  RSpec.configure do |config|
10
9
  config.mock_framework = :flexmock
11
10
  end
12
11
 
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
12
+ describe "mocking with RSpec" do
13
+ it "passes when it should" do
14
+ receiver = flexmock('receiver')
15
+ receiver.should_receive(:message).once
16
+ receiver.message
18
17
  end
19
18
  end
20
19
  """
21
- When I run "rspec ./flexmock_example_spec.rb"
20
+ When I run `rspec example_spec.rb`
22
21
  Then the examples should all pass
22
+
23
+ Scenario: failing message expecation
24
+ Given a file named "example_spec.rb" with:
25
+ """
26
+ RSpec.configure do |config|
27
+ config.mock_framework = :flexmock
28
+ end
29
+
30
+ describe "mocking with RSpec" do
31
+ it "fails when it should" do
32
+ receiver = flexmock('receiver')
33
+ receiver.should_receive(:message).once
34
+ end
35
+ end
36
+ """
37
+ When I run `rspec example_spec.rb`
38
+ Then the output should contain "1 example, 1 failure"
39
+
40
+ Scenario: failing message expectation in pending block (remains pending)
41
+ Given a file named "example_spec.rb" with:
42
+ """
43
+ RSpec.configure do |config|
44
+ config.mock_framework = :flexmock
45
+ end
46
+
47
+ describe "failed message expectation in a pending block" do
48
+ it "is listed as pending" do
49
+ pending do
50
+ receiver = flexmock('receiver')
51
+ receiver.should_receive(:message).once
52
+ end
53
+ end
54
+ end
55
+ """
56
+ When I run `rspec example_spec.rb`
57
+ Then the output should contain "1 example, 0 failures, 1 pending"
23
58
  And the exit status should be 0
59
+
60
+ Scenario: passing message expectation in pending block (fails)
61
+ Given a file named "example_spec.rb" with:
62
+ """
63
+ RSpec.configure do |config|
64
+ config.mock_framework = :flexmock
65
+ end
66
+
67
+ describe "passing message expectation in a pending block" do
68
+ it "fails with FIXED" do
69
+ pending do
70
+ receiver = flexmock('receiver')
71
+ receiver.should_receive(:message).once
72
+ receiver.message
73
+ end
74
+ end
75
+ end
76
+ """
77
+ When I run `rspec example_spec.rb`
78
+ Then the output should contain "FIXED"
79
+ Then the output should contain "1 example, 1 failure"
80
+ And the exit status should be 1
81
+
82
+ Scenario: accessing RSpec.configuration.mock_framework.framework_name
83
+ Given a file named "example_spec.rb" with:
84
+ """
85
+ RSpec.configure do |config|
86
+ config.mock_framework = :flexmock
87
+ end
88
+
89
+ describe "RSpec.configuration.mock_framework.framework_name" do
90
+ it "returns :flexmock" do
91
+ RSpec.configuration.mock_framework.framework_name.should eq(:flexmock)
92
+ end
93
+ end
94
+ """
95
+ When I run `rspec example_spec.rb`
96
+ Then the examples should all pass