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,262 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec::Core
|
4
|
-
RSpec.describe OptionParser do
|
5
|
-
let(:output_file){ mock File }
|
6
|
-
|
7
|
-
before do
|
8
|
-
allow(RSpec).to receive(:deprecate)
|
9
|
-
allow(File).to receive(:open).with("foo.txt",'w') { (output_file) }
|
10
|
-
end
|
11
|
-
|
12
|
-
it "does not parse empty args" do
|
13
|
-
parser = Parser.new
|
14
|
-
expect(OptionParser).not_to receive(:new)
|
15
|
-
parser.parse([])
|
16
|
-
end
|
17
|
-
|
18
|
-
it "proposes you to use --help and returns an error on incorrect argument" do
|
19
|
-
parser = Parser.new
|
20
|
-
option = "--my_wrong_arg"
|
21
|
-
|
22
|
-
expect(parser).to receive(:abort) do |msg|
|
23
|
-
expect(msg).to include('use --help', option)
|
24
|
-
end
|
25
|
-
|
26
|
-
parser.parse([option])
|
27
|
-
end
|
28
|
-
|
29
|
-
{
|
30
|
-
'--init' => ['-i','--I'],
|
31
|
-
'--default-path' => ['-d'],
|
32
|
-
'--dry-run' => ['-d'],
|
33
|
-
'--drb-port' => ['-d'],
|
34
|
-
}.each do |long, shorts|
|
35
|
-
shorts.each do |option|
|
36
|
-
it "won't parse #{option} as a shorthand for #{long}" do
|
37
|
-
parser = Parser.new
|
38
|
-
|
39
|
-
expect(parser).to receive(:abort) do |msg|
|
40
|
-
expect(msg).to include('use --help', option)
|
41
|
-
end
|
42
|
-
|
43
|
-
parser.parse([option])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "--default_path" do
|
49
|
-
it "gets converted to --default-path" do
|
50
|
-
options = Parser.parse(%w[--default_path foo])
|
51
|
-
expect(options[:default_path]).to eq "foo"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "--line_number" do
|
56
|
-
it "gets converted to --line-number" do
|
57
|
-
options = Parser.parse(%w[--line_number 3])
|
58
|
-
expect(options[:line_numbers]).to eq ["3"]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
describe "--default-path" do
|
64
|
-
it "sets the default path where RSpec looks for examples" do
|
65
|
-
options = Parser.parse(%w[--default-path foo])
|
66
|
-
expect(options[:default_path]).to eq "foo"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
%w[--line-number -l].each do |option|
|
71
|
-
describe option do
|
72
|
-
it "sets the line number of an example to run" do
|
73
|
-
options = Parser.parse([option, "3"])
|
74
|
-
expect(options[:line_numbers]).to eq ["3"]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
%w[--format -f].each do |option|
|
80
|
-
describe option do
|
81
|
-
it "defines the formatter" do
|
82
|
-
options = Parser.parse([option, 'doc'])
|
83
|
-
expect(options[:formatters].first).to eq(["doc"])
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
%w[--out -o].each do |option|
|
89
|
-
describe option do
|
90
|
-
let(:options) { Parser.parse([option, 'out.txt']) }
|
91
|
-
|
92
|
-
it "sets the output stream for the formatter" do
|
93
|
-
expect(options[:formatters].last).to eq(['progress', 'out.txt'])
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with multiple formatters" do
|
97
|
-
context "after last formatter" do
|
98
|
-
it "sets the output stream for the last formatter" do
|
99
|
-
options = Parser.parse(['-f', 'progress', '-f', 'doc', option, 'out.txt'])
|
100
|
-
expect(options[:formatters][0]).to eq(['progress'])
|
101
|
-
expect(options[:formatters][1]).to eq(['doc', 'out.txt'])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "after first formatter" do
|
106
|
-
it "sets the output stream for the first formatter" do
|
107
|
-
options = Parser.parse(['-f', 'progress', option, 'out.txt', '-f', 'doc'])
|
108
|
-
expect(options[:formatters][0]).to eq(['progress', 'out.txt'])
|
109
|
-
expect(options[:formatters][1]).to eq(['doc'])
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
%w[--example -e].each do |option|
|
117
|
-
describe option do
|
118
|
-
it "escapes the arg" do
|
119
|
-
options = Parser.parse([option, "this (and that)"])
|
120
|
-
expect(options[:full_description].length).to eq(1)
|
121
|
-
expect("this (and that)").to match(options[:full_description].first)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
%w[--pattern -P].each do |option|
|
127
|
-
describe option do
|
128
|
-
it "sets the filename pattern" do
|
129
|
-
options = Parser.parse([option, 'spec/**/*.spec'])
|
130
|
-
expect(options[:pattern]).to eq('spec/**/*.spec')
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
%w[--tag -t].each do |option|
|
136
|
-
describe option do
|
137
|
-
context "without ~" do
|
138
|
-
it "treats no value as true" do
|
139
|
-
options = Parser.parse([option, 'foo'])
|
140
|
-
expect(options[:inclusion_filter]).to eq(:foo => true)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "treats 'true' as true" do
|
144
|
-
options = Parser.parse([option, 'foo:true'])
|
145
|
-
expect(options[:inclusion_filter]).to eq(:foo => true)
|
146
|
-
end
|
147
|
-
|
148
|
-
it "treats 'nil' as nil" do
|
149
|
-
options = Parser.parse([option, 'foo:nil'])
|
150
|
-
expect(options[:inclusion_filter]).to eq(:foo => nil)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "treats 'false' as false" do
|
154
|
-
options = Parser.parse([option, 'foo:false'])
|
155
|
-
expect(options[:inclusion_filter]).to eq(:foo => false)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "merges muliple invocations" do
|
159
|
-
options = Parser.parse([option, 'foo:false', option, 'bar:true', option, 'foo:true'])
|
160
|
-
expect(options[:inclusion_filter]).to eq(:foo => true, :bar => true)
|
161
|
-
end
|
162
|
-
|
163
|
-
it "treats 'any_string' as 'any_string'" do
|
164
|
-
options = Parser.parse([option, 'foo:any_string'])
|
165
|
-
expect(options[:inclusion_filter]).to eq(:foo => 'any_string')
|
166
|
-
end
|
167
|
-
|
168
|
-
it "treats ':any_sym' as :any_sym" do
|
169
|
-
options = Parser.parse([option, 'foo::any_sym'])
|
170
|
-
expect(options[:inclusion_filter]).to eq(:foo => :any_sym)
|
171
|
-
end
|
172
|
-
|
173
|
-
it "treats '42' as 42" do
|
174
|
-
options = Parser.parse([option, 'foo:42'])
|
175
|
-
expect(options[:inclusion_filter]).to eq(:foo => 42)
|
176
|
-
end
|
177
|
-
|
178
|
-
it "treats '3.146' as 3.146" do
|
179
|
-
options = Parser.parse([option, 'foo:3.146'])
|
180
|
-
expect(options[:inclusion_filter]).to eq(:foo => 3.146)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context "with ~" do
|
185
|
-
it "treats no value as true" do
|
186
|
-
options = Parser.parse([option, '~foo'])
|
187
|
-
expect(options[:exclusion_filter]).to eq(:foo => true)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "treats 'true' as true" do
|
191
|
-
options = Parser.parse([option, '~foo:true'])
|
192
|
-
expect(options[:exclusion_filter]).to eq(:foo => true)
|
193
|
-
end
|
194
|
-
|
195
|
-
it "treats 'nil' as nil" do
|
196
|
-
options = Parser.parse([option, '~foo:nil'])
|
197
|
-
expect(options[:exclusion_filter]).to eq(:foo => nil)
|
198
|
-
end
|
199
|
-
|
200
|
-
it "treats 'false' as false" do
|
201
|
-
options = Parser.parse([option, '~foo:false'])
|
202
|
-
expect(options[:exclusion_filter]).to eq(:foo => false)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
describe "--order" do
|
209
|
-
it "is nil by default" do
|
210
|
-
expect(Parser.parse([])[:order]).to be_nil
|
211
|
-
end
|
212
|
-
|
213
|
-
%w[rand random].each do |option|
|
214
|
-
context "with #{option}" do
|
215
|
-
it "defines the order as random" do
|
216
|
-
options = Parser.parse(['--order', option])
|
217
|
-
expect(options[:order]).to eq(option)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "--seed" do
|
224
|
-
it "sets the order to rand:SEED" do
|
225
|
-
options = Parser.parse(%w[--seed 123])
|
226
|
-
expect(options[:order]).to eq("rand:123")
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
describe '--profile' do
|
231
|
-
it 'sets profile_examples to true by default' do
|
232
|
-
options = Parser.parse(%w[--profile])
|
233
|
-
expect(options[:profile_examples]).to eq true
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'sets profile_examples to supplied int' do
|
237
|
-
options = Parser.parse(%w[--profile 10])
|
238
|
-
expect(options[:profile_examples]).to eq 10
|
239
|
-
end
|
240
|
-
|
241
|
-
it 'sets profile_examples to true when accidentally combined with path' do
|
242
|
-
allow_warning
|
243
|
-
options = Parser.parse(%w[--profile some/path])
|
244
|
-
expect(options[:profile_examples]).to eq true
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'warns when accidentally combined with path' do
|
248
|
-
expect_warning_without_call_site "Non integer specified as profile count"
|
249
|
-
options = Parser.parse(%w[--profile some/path])
|
250
|
-
expect(options[:profile_examples]).to eq true
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe '--warning' do
|
255
|
-
it 'enables warnings' do
|
256
|
-
options = Parser.parse(%w[--warnings])
|
257
|
-
expect(options[:warnings]).to eq true
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Core
|
5
|
-
module Ordering
|
6
|
-
RSpec.describe Identity do
|
7
|
-
it "does not affect the ordering of the items" do
|
8
|
-
expect(Identity.new.order([1, 2, 3])).to eq([1, 2, 3])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
RSpec.describe Random do
|
13
|
-
describe '.order' do
|
14
|
-
subject { described_class.new(configuration) }
|
15
|
-
|
16
|
-
let(:configuration) { RSpec::Core::Configuration.new }
|
17
|
-
let(:items) { 10.times.map { |n| n } }
|
18
|
-
let(:shuffled_items) { subject.order items }
|
19
|
-
|
20
|
-
it 'shuffles the items randomly' do
|
21
|
-
expect(shuffled_items).to match_array items
|
22
|
-
expect(shuffled_items).to_not eq items
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'given multiple calls' do
|
26
|
-
it 'returns the items in the same order' do
|
27
|
-
expect(subject.order(items)).to eq shuffled_items
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'given randomization has been seeded explicitly' do
|
32
|
-
before { @seed = srand }
|
33
|
-
after { srand @seed }
|
34
|
-
|
35
|
-
it "does not affect the global random number generator" do
|
36
|
-
srand 123
|
37
|
-
val1, val2 = rand(1_000), rand(1_000)
|
38
|
-
|
39
|
-
subject
|
40
|
-
|
41
|
-
srand 123
|
42
|
-
subject.order items
|
43
|
-
expect(rand(1_000)).to eq(val1)
|
44
|
-
subject.order items
|
45
|
-
expect(rand(1_000)).to eq(val2)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
RSpec.describe Custom do
|
52
|
-
it 'uses the block to order the list' do
|
53
|
-
strategy = Custom.new(proc { |list| list.reverse })
|
54
|
-
|
55
|
-
expect(strategy.order([1, 2, 3, 4])).to eq([4, 3, 2, 1])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
RSpec.describe Registry do
|
60
|
-
let(:configuration) { Configuration.new }
|
61
|
-
subject(:registry) { Registry.new(configuration) }
|
62
|
-
|
63
|
-
describe "#used_random_seed?" do
|
64
|
-
it 'returns false if the random orderer has not been used' do
|
65
|
-
expect(registry.used_random_seed?).to be false
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns false if the random orderer has been fetched but not used' do
|
69
|
-
expect(registry.fetch(:random)).to be_a(Random)
|
70
|
-
expect(registry.used_random_seed?).to be false
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns true if the random orderer has been used' do
|
74
|
-
registry.fetch(:random).order([1, 2])
|
75
|
-
expect(registry.used_random_seed?).to be true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#fetch" do
|
80
|
-
it "gives the registered ordering when called with a symbol" do
|
81
|
-
ordering = Object.new
|
82
|
-
subject.register(:falcon, ordering)
|
83
|
-
|
84
|
-
expect(subject.fetch(:falcon)).to be ordering
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when given an unrecognized symbol" do
|
88
|
-
it 'invokes the given block and returns its value' do
|
89
|
-
expect(subject.fetch(:falcon) { :fallback }).to eq(:fallback)
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'raises an error if no block is given' do
|
93
|
-
expect {
|
94
|
-
subject.fetch(:falcon)
|
95
|
-
}.to raise_error(IndexError)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe "an example" do
|
4
|
-
context "declared pending with metadata" do
|
5
|
-
it "uses the value assigned to :pending as the message" do
|
6
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
7
|
-
example "example", :pending => 'just because' do
|
8
|
-
fail
|
9
|
-
end
|
10
|
-
end
|
11
|
-
example = group.examples.first
|
12
|
-
example.run(group.new, double.as_null_object)
|
13
|
-
expect(example).to be_pending_with('just because')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "sets the message to 'No reason given' if :pending => true" do
|
17
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
18
|
-
example "example", :pending => true do
|
19
|
-
fail
|
20
|
-
end
|
21
|
-
end
|
22
|
-
example = group.examples.first
|
23
|
-
example.run(group.new, double.as_null_object)
|
24
|
-
expect(example).to be_pending_with('No reason given')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with no block" do
|
29
|
-
it "is listed as pending with 'Not yet implemented'" do
|
30
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
31
|
-
it "has no block"
|
32
|
-
end
|
33
|
-
example = group.examples.first
|
34
|
-
example.run(group.new, double.as_null_object)
|
35
|
-
expect(example).to be_skipped_with('Not yet implemented')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with no args" do
|
40
|
-
it "is listed as pending with the default message" do
|
41
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
42
|
-
it "does something" do
|
43
|
-
pending
|
44
|
-
fail
|
45
|
-
end
|
46
|
-
end
|
47
|
-
example = group.examples.first
|
48
|
-
example.run(group.new, double.as_null_object)
|
49
|
-
expect(example).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "fails when the rest of the example passes" do
|
53
|
-
called = false
|
54
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
55
|
-
it "does something" do
|
56
|
-
pending
|
57
|
-
called = true
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
example = group.examples.first
|
62
|
-
example.run(group.new, double.as_null_object)
|
63
|
-
expect(called).to eq(true)
|
64
|
-
result = example.metadata[:execution_result]
|
65
|
-
expect(result[:pending_fixed]).to eq(true)
|
66
|
-
expect(result[:status]).to eq("failed")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "with no docstring" do
|
71
|
-
context "declared with the pending method" do
|
72
|
-
it "does not have an auto-generated description" do
|
73
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
74
|
-
it "checks something" do
|
75
|
-
expect((3+4)).to eq(7)
|
76
|
-
end
|
77
|
-
pending do
|
78
|
-
expect("string".reverse).to eq("gnirts")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
example = group.examples.last
|
82
|
-
example.run(group.new, double.as_null_object)
|
83
|
-
expect(example.description).to match(/example at/)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context "after another example with some assertion" do
|
88
|
-
it "does not show any message" do
|
89
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
90
|
-
it "checks something" do
|
91
|
-
expect((3+4)).to eq(7)
|
92
|
-
end
|
93
|
-
specify do
|
94
|
-
pending
|
95
|
-
end
|
96
|
-
end
|
97
|
-
example = group.examples.last
|
98
|
-
example.run(group.new, double.as_null_object)
|
99
|
-
expect(example.description).to match(/example at/)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "with a message" do
|
105
|
-
it "is listed as pending with the supplied message" do
|
106
|
-
group = RSpec::Core::ExampleGroup.describe('group') do
|
107
|
-
it "does something" do
|
108
|
-
pending("just because")
|
109
|
-
fail
|
110
|
-
end
|
111
|
-
end
|
112
|
-
example = group.examples.first
|
113
|
-
example.run(group.new, double.as_null_object)
|
114
|
-
expect(example).to be_pending_with('just because')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|