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.
- data/.travis.yml +7 -0
- data/Gemfile +12 -14
- data/README.md +4 -1
- data/Rakefile +29 -12
- data/cucumber.yml +1 -1
- data/features/.nav +15 -9
- data/features/Autotest.md +31 -7
- data/features/Changelog.md +46 -3
- data/features/Upgrade.md +35 -2
- data/features/command_line/README.md +22 -0
- data/features/command_line/configure.feature +2 -2
- data/features/command_line/example_name_option.feature +10 -10
- data/features/command_line/exit_status.feature +4 -4
- data/features/command_line/format_option.feature +4 -4
- data/features/command_line/line_number_appended_to_path.feature +11 -11
- data/features/command_line/line_number_option.feature +2 -2
- data/features/command_line/rake_task.feature +3 -3
- data/features/command_line/tag.feature +30 -14
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +3 -3
- data/features/configuration/fail_fast.feature +3 -3
- data/features/configuration/read_options_from_file.feature +4 -4
- data/features/example_groups/basic_structure.feature +11 -15
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +21 -17
- data/features/expectation_framework_integration/configure_expectation_framework.feature +15 -4
- data/features/filtering/exclusion_filters.feature +28 -4
- data/features/filtering/{implicit_filters.feature → if_and_unless.feature} +9 -7
- data/features/filtering/inclusion_filters.feature +26 -3
- data/features/filtering/run_all_when_everything_filtered.feature +2 -2
- data/features/formatters/custom_formatter.feature +1 -1
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +2 -2
- data/features/helper_methods/let.feature +2 -2
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +18 -11
- data/features/hooks/before_and_after_hooks.feature +15 -19
- data/features/hooks/filtering.feature +160 -124
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +2 -2
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +1 -1
- data/features/mock_framework_integration/use_flexmock.feature +83 -10
- data/features/mock_framework_integration/use_mocha.feature +84 -10
- data/features/mock_framework_integration/use_rr.feature +85 -10
- data/features/mock_framework_integration/use_rspec.feature +84 -10
- data/features/pending/pending_examples.feature +8 -8
- data/features/spec_files/arbitrary_file_suffix.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +11 -1
- data/features/subject/attribute_of_subject.feature +24 -4
- data/features/subject/explicit_subject.feature +5 -5
- data/features/subject/implicit_receiver.feature +2 -2
- data/features/subject/implicit_subject.feature +2 -2
- data/features/support/env.rb +6 -1
- data/lib/rspec/core/backward_compatibility.rb +12 -2
- data/lib/rspec/core/command_line.rb +2 -5
- data/lib/rspec/core/configuration.rb +70 -38
- data/lib/rspec/core/configuration_options.rb +6 -23
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/example.rb +29 -21
- data/lib/rspec/core/example_group.rb +40 -8
- data/lib/rspec/core/extensions/object.rb +0 -1
- data/lib/rspec/core/formatters/base_formatter.rb +6 -0
- data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/hooks.rb +14 -4
- data/lib/rspec/core/metadata.rb +1 -1
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +9 -2
- data/lib/rspec/core/pending.rb +10 -3
- data/lib/rspec/core/reporter.rb +2 -2
- data/lib/rspec/core/runner.rb +38 -13
- data/lib/rspec/core/shared_example_group.rb +18 -4
- data/lib/rspec/core/subject.rb +4 -6
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +70 -18
- data/lib/rspec/core.rb +29 -0
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +3 -5
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/rspec/core/command_line_spec.rb +36 -2
- data/spec/rspec/core/configuration_spec.rb +150 -70
- data/spec/rspec/core/deprecations_spec.rb +21 -0
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +213 -56
- data/spec/rspec/core/example_spec.rb +110 -0
- data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -2
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +9 -0
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/hooks_spec.rb +86 -0
- data/spec/rspec/core/metadata_spec.rb +7 -7
- data/spec/rspec/core/option_parser_spec.rb +26 -15
- data/spec/rspec/core/pending_example_spec.rb +12 -51
- data/spec/rspec/core/reporter_spec.rb +19 -3
- data/spec/rspec/core/resources/formatter_specs.rb +7 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +42 -10
- data/spec/rspec/core/shared_example_group_spec.rb +57 -21
- data/spec/rspec/core/subject_spec.rb +32 -11
- data/spec/rspec/core/world_spec.rb +147 -15
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +22 -2
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +35 -16
- 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)
|
|
15
|
+
config.before(:each, :foo => :bar) do
|
|
16
|
+
invoked_hooks << :before_each_foo_bar
|
|
17
|
+
end
|
|
13
18
|
end
|
|
14
19
|
|
|
15
|
-
describe "
|
|
16
|
-
|
|
17
|
-
it("example 2", :foo => :bar) { }
|
|
18
|
-
end
|
|
20
|
+
describe "a filtered before :each hook" do
|
|
21
|
+
let(:invoked_hooks) { [] }
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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)
|
|
47
|
+
config.after(:each, :foo => :bar) do
|
|
48
|
+
raise "boom!"
|
|
49
|
+
end
|
|
45
50
|
end
|
|
46
51
|
|
|
47
|
-
describe "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
78
|
+
order << :before_around_each_foo_bar
|
|
78
79
|
example.run
|
|
79
|
-
|
|
80
|
+
order.should == [:before_around_each_foo_bar, :example]
|
|
80
81
|
end
|
|
81
82
|
end
|
|
82
83
|
|
|
83
|
-
describe "
|
|
84
|
-
|
|
85
|
-
it("example 2", :foo => :bar) { }
|
|
86
|
-
end
|
|
84
|
+
describe "a filtered around(:each) hook" do
|
|
85
|
+
let(:order) { [] }
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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) {
|
|
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 "
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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)
|
|
151
|
+
config.after(:all, :foo => :bar) do
|
|
152
|
+
puts "after :all"
|
|
153
|
+
end
|
|
157
154
|
end
|
|
158
155
|
|
|
159
|
-
describe "
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
176
|
-
Then the
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
+
|
|
@@ -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
|
|
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
|
-
|
|
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:
|
|
7
|
-
Given a file named "
|
|
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 "
|
|
14
|
-
it "
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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
|