rspec-core 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/Changelog.md +297 -57
- data/README.md +16 -13
- data/lib/rspec/core.rb +55 -84
- data/lib/rspec/core/backport_random.rb +35 -3
- data/lib/rspec/core/backtrace_formatter.rb +4 -13
- data/lib/rspec/core/configuration.rb +330 -114
- data/lib/rspec/core/configuration_options.rb +38 -22
- data/lib/rspec/core/drb.rb +111 -0
- data/lib/rspec/core/dsl.rb +8 -2
- data/lib/rspec/core/example.rb +203 -94
- data/lib/rspec/core/example_group.rb +344 -316
- data/lib/rspec/core/filter_manager.rb +135 -90
- data/lib/rspec/core/flat_map.rb +1 -0
- data/lib/rspec/core/formatters.rb +50 -14
- data/lib/rspec/core/formatters/base_formatter.rb +32 -138
- data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
- data/lib/rspec/core/formatters/console_codes.rb +65 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
- data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
- data/lib/rspec/core/formatters/helpers.rb +15 -9
- data/lib/rspec/core/formatters/html_formatter.rb +17 -16
- data/lib/rspec/core/formatters/html_printer.rb +1 -0
- data/lib/rspec/core/formatters/json_formatter.rb +18 -20
- data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
- data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
- data/lib/rspec/core/hooks.rb +131 -125
- data/lib/rspec/core/memoized_helpers.rb +31 -26
- data/lib/rspec/core/metadata.rb +277 -184
- data/lib/rspec/core/metadata_filter.rb +86 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
- data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
- data/lib/rspec/core/mocking_adapters/null.rb +1 -1
- data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
- data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
- data/lib/rspec/core/notifications.rb +435 -24
- data/lib/rspec/core/option_parser.rb +16 -25
- data/lib/rspec/core/ordering.rb +3 -1
- data/lib/rspec/core/pending.rb +57 -33
- data/lib/rspec/core/project_initializer.rb +2 -0
- data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
- data/lib/rspec/core/rake_task.rb +45 -20
- data/lib/rspec/core/reporter.rb +50 -22
- data/lib/rspec/core/ruby_project.rb +1 -0
- data/lib/rspec/core/runner.rb +93 -39
- data/lib/rspec/core/shared_context.rb +7 -5
- data/lib/rspec/core/shared_example_group.rb +85 -77
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +3 -1
- data/lib/rspec/core/warnings.rb +35 -17
- data/lib/rspec/core/world.rb +57 -5
- metadata +56 -369
- metadata.gz.sig +3 -3
- data/features/README.md +0 -13
- data/features/Upgrade.md +0 -352
- data/features/command_line/README.md +0 -25
- data/features/command_line/dry_run.feature +0 -29
- data/features/command_line/example_name_option.feature +0 -97
- data/features/command_line/exit_status.feature +0 -82
- data/features/command_line/fail_fast.feature +0 -26
- data/features/command_line/format_option.feature +0 -75
- data/features/command_line/init.feature +0 -57
- data/features/command_line/line_number_appended_to_path.feature +0 -140
- data/features/command_line/line_number_option.feature +0 -58
- data/features/command_line/order.feature +0 -25
- data/features/command_line/pattern_option.feature +0 -49
- data/features/command_line/rake_task.feature +0 -122
- data/features/command_line/randomization.feature +0 -63
- data/features/command_line/require_option.feature +0 -43
- data/features/command_line/ruby.feature +0 -23
- data/features/command_line/tag.feature +0 -98
- data/features/command_line/warnings_option.feature +0 -29
- data/features/configuration/alias_example_to.feature +0 -39
- data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/deprecation_stream.feature +0 -58
- data/features/configuration/enable_global_dsl.feature +0 -54
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/failure_exit_code.feature +0 -36
- data/features/configuration/order_and_seed.feature +0 -3
- data/features/configuration/output_stream.feature +0 -24
- data/features/configuration/overriding_global_ordering.feature +0 -93
- data/features/configuration/pattern.feature +0 -38
- data/features/configuration/profile.feature +0 -220
- data/features/configuration/read_options_from_file.feature +0 -90
- data/features/configuration/run_all_when_everything_filtered.feature +0 -76
- data/features/example_groups/aliasing.feature +0 -48
- data/features/example_groups/basic_structure.feature +0 -55
- data/features/example_groups/shared_context.feature +0 -74
- data/features/example_groups/shared_examples.feature +0 -286
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -135
- data/features/filtering/if_and_unless.feature +0 -138
- data/features/filtering/inclusion_filters.feature +0 -101
- data/features/formatters/configurable_colors.feature +0 -31
- data/features/formatters/custom_formatter.feature +0 -68
- data/features/formatters/json_formatter.feature +0 -30
- data/features/formatters/regression_tests.feature +0 -95
- data/features/formatters/text_formatter.feature +0 -46
- data/features/helper_methods/arbitrary_methods.feature +0 -40
- data/features/helper_methods/let.feature +0 -50
- data/features/helper_methods/modules.feature +0 -146
- data/features/hooks/around_hooks.feature +0 -344
- data/features/hooks/before_and_after_hooks.feature +0 -427
- data/features/hooks/filtering.feature +0 -232
- data/features/metadata/current_example.feature +0 -56
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -100
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -94
- data/features/mock_framework_integration/use_mocha.feature +0 -95
- data/features/mock_framework_integration/use_rr.feature +0 -96
- data/features/mock_framework_integration/use_rspec.feature +0 -95
- data/features/pending_and_skipped_examples/README.md +0 -3
- data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
- data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -83
- data/features/subject/explicit_subject.feature +0 -101
- data/features/subject/implicit_subject.feature +0 -63
- data/features/subject/one_liner_syntax.feature +0 -71
- data/features/support/env.rb +0 -21
- data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
- data/features/support/rubinius.rb +0 -6
- data/lib/rspec/core/command_line.rb +0 -35
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
- data/lib/rspec/core/shared_example_group/collection.rb +0 -27
- data/spec/command_line/order_spec.rb +0 -211
- data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
- data/spec/rspec/core/command_line_spec.rb +0 -112
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -409
- data/spec/rspec/core/configuration_spec.rb +0 -1479
- data/spec/rspec/core/drb_command_line_spec.rb +0 -102
- data/spec/rspec/core/drb_options_spec.rb +0 -193
- data/spec/rspec/core/dsl_spec.rb +0 -88
- data/spec/rspec/core/example_group_spec.rb +0 -1533
- data/spec/rspec/core/example_spec.rb +0 -642
- data/spec/rspec/core/filter_manager_spec.rb +0 -229
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
- data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
- data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
- data/spec/rspec/core/formatters/html_formatted.html +0 -397
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
- data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
- data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
- data/spec/rspec/core/formatters_spec.rb +0 -120
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -294
- data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
- data/spec/rspec/core/metadata_spec.rb +0 -491
- data/spec/rspec/core/option_parser_spec.rb +0 -262
- data/spec/rspec/core/ordering_spec.rb +0 -102
- data/spec/rspec/core/pending_example_spec.rb +0 -117
- data/spec/rspec/core/pending_spec.rb +0 -8
- data/spec/rspec/core/project_initializer_spec.rb +0 -73
- data/spec/rspec/core/rake_task_spec.rb +0 -146
- data/spec/rspec/core/random_spec.rb +0 -47
- data/spec/rspec/core/reporter_spec.rb +0 -155
- data/spec/rspec/core/resources/a_bar.rb +0 -0
- data/spec/rspec/core/resources/a_foo.rb +0 -0
- data/spec/rspec/core/resources/a_spec.rb +0 -1
- data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
- data/spec/rspec/core/resources/formatter_specs.rb +0 -58
- data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
- data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
- data/spec/rspec/core/ruby_project_spec.rb +0 -26
- data/spec/rspec/core/runner_spec.rb +0 -151
- data/spec/rspec/core/shared_context_spec.rb +0 -102
- data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
- data/spec/rspec/core/shared_example_group_spec.rb +0 -114
- data/spec/rspec/core/warnings_spec.rb +0 -29
- data/spec/rspec/core/world_spec.rb +0 -142
- data/spec/rspec/core_spec.rb +0 -91
- data/spec/spec_helper.rb +0 -160
- data/spec/support/config_options_helper.rb +0 -13
- data/spec/support/formatter_support.rb +0 -83
- data/spec/support/helper_methods.rb +0 -26
- data/spec/support/isolate_load_path_mutation.rb +0 -5
- data/spec/support/isolated_directory.rb +0 -10
- data/spec/support/isolated_home_directory.rb +0 -16
- data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
- data/spec/support/matchers.rb +0 -85
- data/spec/support/mathn_integration_support.rb +0 -12
- data/spec/support/old_style_formatter_example.rb +0 -69
- data/spec/support/shared_example_groups.rb +0 -13
- data/spec/support/spec_files.rb +0 -44
- data/spec/support/stderr_splitter.rb +0 -36
@@ -1,232 +0,0 @@
|
|
1
|
-
Feature: filters
|
2
|
-
|
3
|
-
`before`, `after`, and `around` hooks defined in the block passed to
|
4
|
-
`RSpec.configure` can be constrained to specific examples and/or groups using
|
5
|
-
metadata as a filter.
|
6
|
-
|
7
|
-
RSpec.configure do |c|
|
8
|
-
c.before(:each, :type => :model) do
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "something", :type => :model do
|
13
|
-
end
|
14
|
-
|
15
|
-
You can also specify metadata using only symbols.
|
16
|
-
|
17
|
-
Scenario: filter `before(:each)` hooks using arbitrary metadata
|
18
|
-
Given a file named "filter_before_each_hooks_spec.rb" with:
|
19
|
-
"""ruby
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.before(:each, :foo => :bar) do
|
22
|
-
invoked_hooks << :before_each_foo_bar
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "a filtered before :each hook" do
|
27
|
-
let(:invoked_hooks) { [] }
|
28
|
-
|
29
|
-
describe "group without matching metadata" do
|
30
|
-
it "does not run the hook" do
|
31
|
-
expect(invoked_hooks).to be_empty
|
32
|
-
end
|
33
|
-
|
34
|
-
it "runs the hook for an example with matching metadata", :foo => :bar do
|
35
|
-
expect(invoked_hooks).to eq([:before_each_foo_bar])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "group with matching metadata", :foo => :bar do
|
40
|
-
it "runs the hook" do
|
41
|
-
expect(invoked_hooks).to eq([:before_each_foo_bar])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
"""
|
46
|
-
When I run `rspec filter_before_each_hooks_spec.rb`
|
47
|
-
Then the examples should all pass
|
48
|
-
|
49
|
-
Scenario: filter `after(:each)` hooks using arbitrary metadata
|
50
|
-
Given a file named "filter_after_each_hooks_spec.rb" with:
|
51
|
-
"""ruby
|
52
|
-
RSpec.configure do |config|
|
53
|
-
config.after(:each, :foo => :bar) do
|
54
|
-
raise "boom!"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "a filtered after :each hook" do
|
59
|
-
describe "group without matching metadata" do
|
60
|
-
it "does not run the hook" do
|
61
|
-
# should pass
|
62
|
-
end
|
63
|
-
|
64
|
-
it "runs the hook for an example with matching metadata", :foo => :bar do
|
65
|
-
# should fail
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "group with matching metadata", :foo => :bar do
|
70
|
-
it "runs the hook" do
|
71
|
-
# should fail
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
"""
|
76
|
-
When I run `rspec filter_after_each_hooks_spec.rb`
|
77
|
-
Then the output should contain "3 examples, 2 failures"
|
78
|
-
|
79
|
-
Scenario: filter around(:each) hooks using arbitrary metadata
|
80
|
-
Given a file named "filter_around_each_hooks_spec.rb" with:
|
81
|
-
"""ruby
|
82
|
-
RSpec.configure do |config|
|
83
|
-
config.around(:each, :foo => :bar) do |example|
|
84
|
-
order << :before_around_each_foo_bar
|
85
|
-
example.run
|
86
|
-
expect(order).to eq([:before_around_each_foo_bar, :example])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "a filtered around(:each) hook" do
|
91
|
-
let(:order) { [] }
|
92
|
-
|
93
|
-
describe "a group without matching metadata" do
|
94
|
-
it "does not run the hook" do
|
95
|
-
expect(order).to be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "runs the hook for an example with matching metadata", :foo => :bar do
|
99
|
-
expect(order).to eq([:before_around_each_foo_bar])
|
100
|
-
order << :example
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "a group with matching metadata", :foo => :bar do
|
105
|
-
it "runs the hook for an example with matching metadata", :foo => :bar do
|
106
|
-
expect(order).to eq([:before_around_each_foo_bar])
|
107
|
-
order << :example
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
"""
|
112
|
-
When I run `rspec filter_around_each_hooks_spec.rb`
|
113
|
-
Then the examples should all pass
|
114
|
-
|
115
|
-
Scenario: filter before(:all) hooks using arbitrary metadata
|
116
|
-
Given a file named "filter_before_all_hooks_spec.rb" with:
|
117
|
-
"""ruby
|
118
|
-
RSpec.configure do |config|
|
119
|
-
config.before(:all, :foo => :bar) { @hook = :before_all_foo_bar }
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "a filtered before(:all) hook" do
|
123
|
-
describe "a group without matching metadata" do
|
124
|
-
it "does not run the hook" do
|
125
|
-
expect(@hook).to be_nil
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "a nested subgroup with matching metadata", :foo => :bar do
|
129
|
-
it "runs the hook" do
|
130
|
-
expect(@hook).to eq(:before_all_foo_bar)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "a group with matching metadata", :foo => :bar do
|
136
|
-
it "runs the hook" do
|
137
|
-
expect(@hook).to eq(:before_all_foo_bar)
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "a nested subgroup" do
|
141
|
-
it "runs the hook" do
|
142
|
-
expect(@hook).to eq(:before_all_foo_bar)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
"""
|
148
|
-
When I run `rspec filter_before_all_hooks_spec.rb`
|
149
|
-
Then the examples should all pass
|
150
|
-
|
151
|
-
Scenario: filter after(:all) hooks using arbitrary metadata
|
152
|
-
Given a file named "filter_after_all_hooks_spec.rb" with:
|
153
|
-
"""ruby
|
154
|
-
example_msgs = []
|
155
|
-
|
156
|
-
RSpec.configure do |config|
|
157
|
-
config.after(:all, :foo => :bar) do
|
158
|
-
puts "after :all"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe "a filtered after(:all) hook" do
|
163
|
-
describe "a group without matching metadata" do
|
164
|
-
it "does not run the hook" do
|
165
|
-
puts "unfiltered"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "a group with matching metadata", :foo => :bar do
|
170
|
-
it "runs the hook" do
|
171
|
-
puts "filtered 1"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "another group without matching metadata" do
|
176
|
-
describe "a nested subgroup with matching metadata", :foo => :bar do
|
177
|
-
it "runs the hook" do
|
178
|
-
puts "filtered 2"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
"""
|
184
|
-
When I run `rspec --format progress filter_after_all_hooks_spec.rb`
|
185
|
-
Then the examples should all pass
|
186
|
-
And the output should contain:
|
187
|
-
"""
|
188
|
-
unfiltered
|
189
|
-
.filtered 1
|
190
|
-
.after :all
|
191
|
-
filtered 2
|
192
|
-
.after :all
|
193
|
-
"""
|
194
|
-
|
195
|
-
Scenario: Use symbols as metadata
|
196
|
-
Given a file named "less_verbose_metadata_filter.rb" with:
|
197
|
-
"""ruby
|
198
|
-
RSpec.configure do |c|
|
199
|
-
c.before(:each, :before_each) { puts "before each" }
|
200
|
-
c.after(:each, :after_each) { puts "after each" }
|
201
|
-
c.around(:each, :around_each) do |example|
|
202
|
-
puts "around each (before)"
|
203
|
-
example.run
|
204
|
-
puts "around each (after)"
|
205
|
-
end
|
206
|
-
c.before(:all, :before_all) { puts "before all" }
|
207
|
-
c.after(:all, :after_all) { puts "after all" }
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "group 1", :before_all, :after_all do
|
211
|
-
it("") { puts "example 1" }
|
212
|
-
it("", :before_each) { puts "example 2" }
|
213
|
-
it("", :after_each) { puts "example 3" }
|
214
|
-
it("", :around_each) { puts "example 4" }
|
215
|
-
end
|
216
|
-
"""
|
217
|
-
When I run `rspec --format progress less_verbose_metadata_filter.rb`
|
218
|
-
Then the examples should all pass
|
219
|
-
And the output should contain:
|
220
|
-
"""
|
221
|
-
before all
|
222
|
-
example 1
|
223
|
-
.before each
|
224
|
-
example 2
|
225
|
-
.example 3
|
226
|
-
after each
|
227
|
-
.around each (before)
|
228
|
-
example 4
|
229
|
-
around each (after)
|
230
|
-
.after all
|
231
|
-
"""
|
232
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
Feature: current example
|
2
|
-
|
3
|
-
You can reference the example object, and access its metadata, using
|
4
|
-
a block argument to it, before and after hooks, let, and subject.
|
5
|
-
|
6
|
-
Scenario: access the example object from within an example
|
7
|
-
Given a file named "spec/example_spec.rb" with:
|
8
|
-
"""ruby
|
9
|
-
describe "example as block arg to it, before, and after" do
|
10
|
-
before do |example|
|
11
|
-
expect(example.description).to eq("is the example object")
|
12
|
-
end
|
13
|
-
|
14
|
-
after do |example|
|
15
|
-
expect(example.description).to eq("is the example object")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "is the example object" do |example|
|
19
|
-
expect(example.description).to eq("is the example object")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "example as block arg to let" do
|
24
|
-
let(:the_description) do |example|
|
25
|
-
example.description
|
26
|
-
end
|
27
|
-
|
28
|
-
it "is the example object" do |example|
|
29
|
-
expect(the_description).to eq("is the example object")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "example as block arg to subject" do
|
34
|
-
subject do |example|
|
35
|
-
example.description
|
36
|
-
end
|
37
|
-
|
38
|
-
it "is the example object" do |example|
|
39
|
-
expect(subject).to eq("is the example object")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "example as block arg to subject with a name" do
|
44
|
-
subject(:the_subject) do |example|
|
45
|
-
example.description
|
46
|
-
end
|
47
|
-
|
48
|
-
it "is the example object" do |example|
|
49
|
-
expect(the_subject).to eq("is the example object")
|
50
|
-
expect(subject).to eq("is the example object")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
"""
|
54
|
-
When I run `rspec spec/example_spec.rb`
|
55
|
-
Then the example should pass
|
56
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
Feature: described class
|
2
|
-
|
3
|
-
If the first argument to the outermost example group is a class, the class is
|
4
|
-
exposed to each example via the described_class() method.
|
5
|
-
|
6
|
-
Scenario: access the described class from the example
|
7
|
-
Given a file named "spec/example_spec.rb" with:
|
8
|
-
"""ruby
|
9
|
-
describe Fixnum do
|
10
|
-
it "is available as described_class" do
|
11
|
-
expect(described_class).to eq(Fixnum)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
"""
|
15
|
-
When I run `rspec spec/example_spec.rb`
|
16
|
-
Then the example should pass
|
17
|
-
|
@@ -1,100 +0,0 @@
|
|
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, you can specify metdata using just symbols.
|
12
|
-
Each symbol passed as an argument to `describe`, `context` or `it` will
|
13
|
-
be a key in the metadata hash, with a corresponding value of `true`.
|
14
|
-
|
15
|
-
Scenario: define group metadata using a hash
|
16
|
-
Given a file named "define_group_metadata_with_hash_spec.rb" with:
|
17
|
-
"""ruby
|
18
|
-
describe "a group with user-defined metadata", :foo => 17 do
|
19
|
-
it 'has access to the metadata in the example' do |example|
|
20
|
-
expect(example.metadata[:foo]).to eq(17)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'does not have access to metadata defined on sub-groups' do |example|
|
24
|
-
expect(example.metadata).not_to include(:bar)
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'a sub-group with user-defined metadata', :bar => 12 do
|
28
|
-
it 'has access to the sub-group metadata' do |example|
|
29
|
-
expect(example.metadata[:foo]).to eq(17)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'also has access to metadata defined on parent groups' do |example|
|
33
|
-
expect(example.metadata[:bar]).to eq(12)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
"""
|
38
|
-
When I run `rspec define_group_metadata_with_hash_spec.rb`
|
39
|
-
Then the examples should all pass
|
40
|
-
|
41
|
-
Scenario: define example metadata using a hash
|
42
|
-
Given a file named "define_example_metadata_with_hash_spec.rb" with:
|
43
|
-
"""ruby
|
44
|
-
describe "a group with no user-defined metadata" do
|
45
|
-
it 'has an example with metadata', :foo => 17 do |example|
|
46
|
-
expect(example.metadata[:foo]).to eq(17)
|
47
|
-
expect(example.metadata).not_to include(:bar)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'has another example with metadata', :bar => 12, :bazz => 33 do |example|
|
51
|
-
expect(example.metadata[:bar]).to eq(12)
|
52
|
-
expect(example.metadata[:bazz]).to eq(33)
|
53
|
-
expect(example.metadata).not_to include(:foo)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
"""
|
57
|
-
When I run `rspec define_example_metadata_with_hash_spec.rb`
|
58
|
-
Then the examples should all pass
|
59
|
-
|
60
|
-
Scenario: override user-defined metadata
|
61
|
-
Given a file named "override_metadata_spec.rb" with:
|
62
|
-
"""ruby
|
63
|
-
describe "a group with user-defined metadata", :foo => 'bar' do
|
64
|
-
it 'can be overridden by an example', :foo => 'bazz' do |example|
|
65
|
-
expect(example.metadata[:foo]).to eq('bazz')
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "a sub-group with an override", :foo => 'goo' do
|
69
|
-
it 'can be overridden by a sub-group' do |example|
|
70
|
-
expect(example.metadata[:foo]).to eq('goo')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
"""
|
75
|
-
When I run `rspec override_metadata_spec.rb`
|
76
|
-
Then the examples should all pass
|
77
|
-
|
78
|
-
Scenario: less verbose metadata
|
79
|
-
Given a file named "less_verbose_metadata_spec.rb" with:
|
80
|
-
"""ruby
|
81
|
-
describe "a group with simple metadata", :fast, :simple, :bug => 73 do
|
82
|
-
it 'has `:fast => true` metadata' do |example|
|
83
|
-
expect(example.metadata[:fast]).to eq(true)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'has `:simple => true` metadata' do |example|
|
87
|
-
expect(example.metadata[:simple]).to eq(true)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'can still use a hash for metadata' do |example|
|
91
|
-
expect(example.metadata[:bug]).to eq(73)
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'can define simple metadata on an example', :special do |example|
|
95
|
-
expect(example.metadata[:special]).to eq(true)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
"""
|
99
|
-
When I run `rspec less_verbose_metadata_spec.rb`
|
100
|
-
Then the examples should all pass
|
@@ -1,106 +0,0 @@
|
|
1
|
-
Feature: mock with an alternative framework
|
2
|
-
|
3
|
-
In addition to rspec, mocha, flexmock, and RR, you can choose an alternate
|
4
|
-
framework as the mocking framework. You (or the framework authors) just needs
|
5
|
-
to provide an adapter that hooks RSpec's events into those of the framework.
|
6
|
-
|
7
|
-
A mock framework adapter must expose three methods:
|
8
|
-
|
9
|
-
* `setup_mocks_for_rspec`
|
10
|
-
* called before each example is run
|
11
|
-
* `verify_mocks_for_rspec`
|
12
|
-
* called after each example is run
|
13
|
-
* this is where message expectation failures should result in an error with
|
14
|
-
the appropriate failure message
|
15
|
-
* `teardown_mocks_for_rspec`
|
16
|
-
* called after `verify_mocks_for_rspec`
|
17
|
-
* use this to clean up resources, restore objects to earlier state, etc
|
18
|
-
* guaranteed to run even if there are failures
|
19
|
-
|
20
|
-
Scenario: Mock with alternate framework
|
21
|
-
Given a file named "expector.rb" with:
|
22
|
-
"""ruby
|
23
|
-
class Expector
|
24
|
-
class << self
|
25
|
-
def expectors
|
26
|
-
@expectors ||= []
|
27
|
-
end
|
28
|
-
|
29
|
-
def clear_expectors
|
30
|
-
expectors.clear
|
31
|
-
end
|
32
|
-
|
33
|
-
def verify_expectors
|
34
|
-
expectors.each {|d| d.verify}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def initialize
|
39
|
-
self.class.expectors << self
|
40
|
-
end
|
41
|
-
|
42
|
-
def expectations
|
43
|
-
@expectations ||= []
|
44
|
-
end
|
45
|
-
|
46
|
-
def expect(message)
|
47
|
-
expectations << message.to_s
|
48
|
-
end
|
49
|
-
|
50
|
-
def verify
|
51
|
-
unless expectations.empty?
|
52
|
-
raise expectations.map {|e|
|
53
|
-
"expected #{e}, but it was never received"
|
54
|
-
}.join("\n")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def method_missing(name, *args, &block)
|
61
|
-
expectations.delete(name.to_s)
|
62
|
-
end
|
63
|
-
|
64
|
-
public
|
65
|
-
|
66
|
-
module RSpecAdapter
|
67
|
-
def setup_mocks_for_rspec
|
68
|
-
# no setup necessary
|
69
|
-
end
|
70
|
-
|
71
|
-
def verify_mocks_for_rspec
|
72
|
-
Expector.verify_expectors.each {|d| d.verify}
|
73
|
-
end
|
74
|
-
|
75
|
-
def teardown_mocks_for_rspec
|
76
|
-
Expector.clear_expectors
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
"""
|
81
|
-
|
82
|
-
Given a file named "example_spec.rb" with:
|
83
|
-
"""ruby
|
84
|
-
require File.expand_path("../expector", __FILE__)
|
85
|
-
|
86
|
-
RSpec.configure do |config|
|
87
|
-
config.mock_framework = Expector::RSpecAdapter
|
88
|
-
end
|
89
|
-
|
90
|
-
describe Expector do
|
91
|
-
it "passes when message is received" do
|
92
|
-
expector = Expector.new
|
93
|
-
expector.expect(:foo)
|
94
|
-
expector.foo
|
95
|
-
end
|
96
|
-
|
97
|
-
it "fails when message is received" do
|
98
|
-
expector = Expector.new
|
99
|
-
expector.expect(:foo)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
"""
|
103
|
-
When I run `rspec example_spec.rb --format doc`
|
104
|
-
Then the exit status should be 1
|
105
|
-
And the output should contain "2 examples, 1 failure"
|
106
|
-
And the output should contain "fails when message is received (FAILED - 1)"
|