rspec-core 2.11.1 → 3.11.0
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/.document +1 -1
- data/.yardopts +3 -1
- data/Changelog.md +1814 -29
- data/{License.txt → LICENSE.md} +6 -4
- data/README.md +197 -48
- data/exe/rspec +2 -23
- data/lib/rspec/autorun.rb +1 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/bisect/coordinator.rb +62 -0
- data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
- data/lib/rspec/core/bisect/fork_runner.rb +138 -0
- data/lib/rspec/core/bisect/server.rb +61 -0
- data/lib/rspec/core/bisect/shell_command.rb +126 -0
- data/lib/rspec/core/bisect/shell_runner.rb +73 -0
- data/lib/rspec/core/bisect/utilities.rb +69 -0
- data/lib/rspec/core/configuration.rb +1846 -407
- data/lib/rspec/core/configuration_options.rb +154 -50
- data/lib/rspec/core/did_you_mean.rb +46 -0
- data/lib/rspec/core/drb.rb +120 -0
- data/lib/rspec/core/dsl.rb +90 -18
- data/lib/rspec/core/example.rb +488 -152
- data/lib/rspec/core/example_group.rb +733 -294
- data/lib/rspec/core/example_status_persister.rb +235 -0
- data/lib/rspec/core/filter_manager.rb +175 -147
- data/lib/rspec/core/flat_map.rb +20 -0
- data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
- data/lib/rspec/core/formatters/base_formatter.rb +32 -130
- data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
- data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
- data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
- data/lib/rspec/core/formatters/console_codes.rb +76 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
- data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
- data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
- data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
- data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
- data/lib/rspec/core/formatters/helpers.rb +93 -14
- data/lib/rspec/core/formatters/html_formatter.rb +104 -415
- data/lib/rspec/core/formatters/html_printer.rb +414 -0
- data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
- data/lib/rspec/core/formatters/json_formatter.rb +102 -0
- data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
- data/lib/rspec/core/formatters/protocol.rb +182 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
- data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
- data/lib/rspec/core/formatters.rb +279 -0
- data/lib/rspec/core/hooks.rb +451 -300
- data/lib/rspec/core/invocations.rb +87 -0
- data/lib/rspec/core/memoized_helpers.rb +580 -0
- data/lib/rspec/core/metadata.rb +395 -173
- data/lib/rspec/core/metadata_filter.rb +255 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
- data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
- data/lib/rspec/core/mocking_adapters/null.rb +14 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
- data/lib/rspec/core/notifications.rb +521 -0
- data/lib/rspec/core/option_parser.rb +208 -64
- data/lib/rspec/core/ordering.rb +169 -0
- data/lib/rspec/core/output_wrapper.rb +29 -0
- data/lib/rspec/core/pending.rb +115 -59
- data/lib/rspec/core/profiler.rb +34 -0
- data/lib/rspec/core/project_initializer/.rspec +1 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
- data/lib/rspec/core/project_initializer.rb +26 -65
- data/lib/rspec/core/rake_task.rb +140 -131
- data/lib/rspec/core/reporter.rb +207 -44
- data/lib/rspec/core/ruby_project.rb +15 -6
- data/lib/rspec/core/runner.rb +180 -44
- data/lib/rspec/core/sandbox.rb +37 -0
- data/lib/rspec/core/set.rb +54 -0
- data/lib/rspec/core/shared_context.rb +25 -19
- data/lib/rspec/core/shared_example_group.rb +229 -54
- data/lib/rspec/core/shell_escape.rb +49 -0
- 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 +40 -0
- data/lib/rspec/core/world.rb +208 -49
- data/lib/rspec/core.rb +166 -80
- data.tar.gz.sig +0 -0
- metadata +230 -445
- metadata.gz.sig +0 -0
- data/exe/autospec +0 -13
- data/features/Autotest.md +0 -38
- data/features/README.md +0 -17
- data/features/Upgrade.md +0 -364
- data/features/command_line/README.md +0 -28
- data/features/command_line/example_name_option.feature +0 -101
- data/features/command_line/exit_status.feature +0 -83
- data/features/command_line/format_option.feature +0 -81
- data/features/command_line/init.feature +0 -18
- 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 -29
- data/features/command_line/pattern_option.feature +0 -31
- data/features/command_line/rake_task.feature +0 -68
- data/features/command_line/ruby.feature +0 -22
- data/features/command_line/tag.feature +0 -91
- data/features/configuration/alias_example_to.feature +0 -48
- data/features/configuration/custom_settings.feature +0 -84
- data/features/configuration/default_path.feature +0 -38
- data/features/configuration/fail_fast.feature +0 -77
- data/features/configuration/read_options_from_file.feature +0 -87
- 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 -204
- data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
- data/features/filtering/exclusion_filters.feature +0 -139
- data/features/filtering/if_and_unless.feature +0 -168
- data/features/filtering/inclusion_filters.feature +0 -105
- data/features/filtering/run_all_when_everything_filtered.feature +0 -46
- data/features/formatters/custom_formatter.feature +0 -36
- 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 -149
- data/features/hooks/around_hooks.feature +0 -343
- data/features/hooks/before_and_after_hooks.feature +0 -423
- data/features/hooks/filtering.feature +0 -234
- data/features/metadata/current_example.feature +0 -17
- data/features/metadata/described_class.feature +0 -17
- data/features/metadata/user_defined.feature +0 -113
- data/features/mock_framework_integration/use_any_framework.feature +0 -106
- data/features/mock_framework_integration/use_flexmock.feature +0 -96
- data/features/mock_framework_integration/use_mocha.feature +0 -97
- data/features/mock_framework_integration/use_rr.feature +0 -98
- data/features/mock_framework_integration/use_rspec.feature +0 -97
- data/features/pending/pending_examples.feature +0 -229
- data/features/spec_files/arbitrary_file_suffix.feature +0 -13
- data/features/step_definitions/additional_cli_steps.rb +0 -30
- data/features/subject/attribute_of_subject.feature +0 -124
- data/features/subject/explicit_subject.feature +0 -82
- data/features/subject/implicit_receiver.feature +0 -29
- data/features/subject/implicit_subject.feature +0 -63
- data/features/support/env.rb +0 -12
- data/lib/autotest/discover.rb +0 -1
- data/lib/autotest/rspec2.rb +0 -73
- data/lib/rspec/core/backward_compatibility.rb +0 -65
- data/lib/rspec/core/command_line.rb +0 -36
- data/lib/rspec/core/deprecation.rb +0 -36
- data/lib/rspec/core/drb_command_line.rb +0 -26
- data/lib/rspec/core/drb_options.rb +0 -87
- data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
- data/lib/rspec/core/extensions/kernel.rb +0 -9
- data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
- data/lib/rspec/core/extensions/ordered.rb +0 -21
- data/lib/rspec/core/extensions.rb +0 -4
- data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
- data/lib/rspec/core/let.rb +0 -110
- data/lib/rspec/core/load_path.rb +0 -3
- data/lib/rspec/core/metadata_hash_builder.rb +0 -97
- data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
- data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
- data/lib/rspec/core/mocking/with_mocha.rb +0 -29
- data/lib/rspec/core/mocking/with_rr.rb +0 -27
- data/lib/rspec/core/mocking/with_rspec.rb +0 -23
- data/lib/rspec/core/subject.rb +0 -219
- data/spec/autotest/discover_spec.rb +0 -19
- data/spec/autotest/failed_results_re_spec.rb +0 -45
- data/spec/autotest/rspec_spec.rb +0 -123
- data/spec/command_line/order_spec.rb +0 -137
- data/spec/rspec/core/command_line_spec.rb +0 -108
- data/spec/rspec/core/command_line_spec_output.txt +0 -0
- data/spec/rspec/core/configuration_options_spec.rb +0 -377
- data/spec/rspec/core/configuration_spec.rb +0 -1196
- data/spec/rspec/core/deprecations_spec.rb +0 -66
- data/spec/rspec/core/drb_command_line_spec.rb +0 -108
- data/spec/rspec/core/drb_options_spec.rb +0 -180
- data/spec/rspec/core/dsl_spec.rb +0 -17
- data/spec/rspec/core/example_group_spec.rb +0 -1098
- data/spec/rspec/core/example_spec.rb +0 -370
- data/spec/rspec/core/filter_manager_spec.rb +0 -256
- data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
- data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
- data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
- data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
- data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
- data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
- data/spec/rspec/core/hooks_spec.rb +0 -250
- data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
- data/spec/rspec/core/let_spec.rb +0 -55
- data/spec/rspec/core/metadata_spec.rb +0 -447
- data/spec/rspec/core/option_parser_spec.rb +0 -166
- data/spec/rspec/core/pending_example_spec.rb +0 -220
- data/spec/rspec/core/project_initializer_spec.rb +0 -130
- data/spec/rspec/core/rake_task_spec.rb +0 -138
- data/spec/rspec/core/reporter_spec.rb +0 -103
- 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 -60
- 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 -24
- data/spec/rspec/core/runner_spec.rb +0 -81
- data/spec/rspec/core/shared_context_spec.rb +0 -67
- data/spec/rspec/core/shared_example_group_spec.rb +0 -84
- data/spec/rspec/core/subject_spec.rb +0 -244
- data/spec/rspec/core/world_spec.rb +0 -144
- data/spec/rspec/core_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -98
- data/spec/support/config_options_helper.rb +0 -24
- data/spec/support/helper_methods.rb +0 -5
- data/spec/support/matchers.rb +0 -65
- data/spec/support/shared_example_groups.rb +0 -41
- data/spec/support/spec_files.rb +0 -44
data/{License.txt → LICENSE.md}
RENAMED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
2
3
|
|
3
|
-
Copyright
|
4
|
-
Copyright
|
5
|
-
Copyright
|
4
|
+
* Copyright © 2012 Chad Humphries, David Chelimsky, Myron Marston
|
5
|
+
* Copyright © 2009 Chad Humphries, David Chelimsky
|
6
|
+
* Copyright © 2006 David Chelimsky, The RSpec Development Team
|
7
|
+
* Copyright © 2005 Steven Baker
|
6
8
|
|
7
9
|
Permission is hereby granted, free of charge, to any person obtaining
|
8
10
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
# rspec-core [![Build Status](https://
|
1
|
+
# rspec-core [![Build Status](https://github.com/rspec/rspec-core/workflows/RSpec%20CI/badge.svg)](https://github.com/rspec/rspec-core/actions) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.svg)](https://codeclimate.com/github/rspec/rspec-core)
|
2
2
|
|
3
3
|
rspec-core provides the structure for writing executable examples of how your
|
4
4
|
code should behave, and an `rspec` command with tools to constrain which
|
5
|
-
examples get run and
|
5
|
+
examples get run and tailor the output.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Install
|
8
8
|
|
9
9
|
gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
|
10
10
|
gem install rspec-core # for rspec-core only
|
11
11
|
rspec --help
|
12
12
|
|
13
|
-
|
13
|
+
Want to run against the `main` branch? You'll need to include the dependent
|
14
|
+
RSpec repos as well. Add the following to your `Gemfile`:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
18
|
+
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'main'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## Basic Structure
|
14
23
|
|
15
24
|
RSpec uses the words "describe" and "it" so we can express concepts like a conversation:
|
16
25
|
|
@@ -18,9 +27,10 @@ RSpec uses the words "describe" and "it" so we can express concepts like a conve
|
|
18
27
|
"It sums the prices of its line items."
|
19
28
|
|
20
29
|
```ruby
|
21
|
-
describe Order do
|
30
|
+
RSpec.describe Order do
|
22
31
|
it "sums the prices of its line items" do
|
23
32
|
order = Order.new
|
33
|
+
|
24
34
|
order.add_entry(LineItem.new(:item => Item.new(
|
25
35
|
:price => Money.new(1.11, :USD)
|
26
36
|
)))
|
@@ -28,7 +38,8 @@ describe Order do
|
|
28
38
|
:price => Money.new(2.22, :USD),
|
29
39
|
:quantity => 2
|
30
40
|
)))
|
31
|
-
|
41
|
+
|
42
|
+
expect(order.total).to eq(Money.new(5.55, :USD))
|
32
43
|
end
|
33
44
|
end
|
34
45
|
```
|
@@ -40,13 +51,13 @@ Under the hood, an example group is a class in which the block passed to
|
|
40
51
|
`describe` is evaluated. The blocks passed to `it` are evaluated in the
|
41
52
|
context of an _instance_ of that class.
|
42
53
|
|
43
|
-
##
|
54
|
+
## Nested Groups
|
44
55
|
|
45
|
-
You can also declare nested
|
56
|
+
You can also declare nested groups using the `describe` or `context`
|
46
57
|
methods:
|
47
58
|
|
48
59
|
```ruby
|
49
|
-
describe Order do
|
60
|
+
RSpec.describe Order do
|
50
61
|
context "with no items" do
|
51
62
|
it "behaves one way" do
|
52
63
|
# ...
|
@@ -61,31 +72,37 @@ describe Order do
|
|
61
72
|
end
|
62
73
|
```
|
63
74
|
|
64
|
-
|
75
|
+
Nested groups are subclasses of the outer example group class, providing
|
76
|
+
the inheritance semantics you'd want for free.
|
77
|
+
|
78
|
+
## Aliases
|
65
79
|
|
66
|
-
You can declare example groups using either `describe` or `context
|
67
|
-
|
80
|
+
You can declare example groups using either `describe` or `context`.
|
81
|
+
For a top level example group, `describe` and `context` are available
|
82
|
+
off of `RSpec`. For backwards compatibility, they are also available
|
83
|
+
off of the `main` object and `Module` unless you disable monkey
|
84
|
+
patching.
|
68
85
|
|
69
86
|
You can declare examples within a group using any of `it`, `specify`, or
|
70
87
|
`example`.
|
71
88
|
|
72
|
-
##
|
89
|
+
## Shared Examples and Contexts
|
73
90
|
|
74
91
|
Declare a shared example group using `shared_examples`, and then include it
|
75
92
|
in any group using `include_examples`.
|
76
93
|
|
77
94
|
```ruby
|
78
|
-
shared_examples "collections" do |collection_class|
|
95
|
+
RSpec.shared_examples "collections" do |collection_class|
|
79
96
|
it "is empty when first created" do
|
80
|
-
collection_class.new.
|
97
|
+
expect(collection_class.new).to be_empty
|
81
98
|
end
|
82
99
|
end
|
83
100
|
|
84
|
-
describe Array do
|
101
|
+
RSpec.describe Array do
|
85
102
|
include_examples "collections", Array
|
86
103
|
end
|
87
104
|
|
88
|
-
describe Hash do
|
105
|
+
RSpec.describe Hash do
|
89
106
|
include_examples "collections", Hash
|
90
107
|
end
|
91
108
|
```
|
@@ -99,10 +116,10 @@ pretty much the same as `shared_examples` and `include_examples`, providing
|
|
99
116
|
more accurate naming when you share hooks, `let` declarations, helper methods,
|
100
117
|
etc, but no examples.
|
101
118
|
|
102
|
-
##
|
119
|
+
## Metadata
|
103
120
|
|
104
121
|
rspec-core stores a metadata hash with every example and group, which
|
105
|
-
contains
|
122
|
+
contains their descriptions, the locations at which they were
|
106
123
|
declared, etc, etc. This hash powers many of rspec-core's features,
|
107
124
|
including output formatters (which access descriptions and locations),
|
108
125
|
and filtering before and after hooks.
|
@@ -111,8 +128,8 @@ Although you probably won't ever need this unless you are writing an
|
|
111
128
|
extension, you can access it from an example like this:
|
112
129
|
|
113
130
|
```ruby
|
114
|
-
it "does something" do
|
115
|
-
example.metadata[:description].
|
131
|
+
it "does something" do |example|
|
132
|
+
expect(example.metadata[:description]).to eq("does something")
|
116
133
|
end
|
117
134
|
```
|
118
135
|
|
@@ -123,60 +140,144 @@ using the `described_class` method, which is a wrapper for
|
|
123
140
|
`example.metadata[:described_class]`.
|
124
141
|
|
125
142
|
```ruby
|
126
|
-
describe Widget do
|
143
|
+
RSpec.describe Widget do
|
127
144
|
example do
|
128
|
-
described_class.
|
145
|
+
expect(described_class).to equal(Widget)
|
129
146
|
end
|
130
147
|
end
|
131
148
|
```
|
132
149
|
|
133
150
|
This is useful in extensions or shared example groups in which the specific
|
134
|
-
class is unknown. Taking the shared
|
151
|
+
class is unknown. Taking the collections shared example group from above, we can
|
135
152
|
clean it up a bit using `described_class`:
|
136
153
|
|
137
154
|
```ruby
|
138
|
-
shared_examples "collections" do
|
155
|
+
RSpec.shared_examples "collections" do
|
139
156
|
it "is empty when first created" do
|
140
|
-
|
157
|
+
expect(described_class.new).to be_empty
|
141
158
|
end
|
142
159
|
end
|
143
160
|
|
144
|
-
describe Array do
|
161
|
+
RSpec.describe Array do
|
145
162
|
include_examples "collections"
|
146
163
|
end
|
147
164
|
|
148
|
-
describe Hash do
|
165
|
+
RSpec.describe Hash do
|
149
166
|
include_examples "collections"
|
150
167
|
end
|
151
168
|
```
|
152
169
|
|
153
|
-
##
|
170
|
+
## A Word on Scope
|
171
|
+
|
172
|
+
RSpec has two scopes:
|
173
|
+
|
174
|
+
* **Example Group**: Example groups are defined by a `describe` or
|
175
|
+
`context` block, which is eagerly evaluated when the spec file is
|
176
|
+
loaded. The block is evaluated in the context of a subclass of
|
177
|
+
`RSpec::Core::ExampleGroup`, or a subclass of the parent example group
|
178
|
+
when you're nesting them.
|
179
|
+
* **Example**: Examples -- typically defined by an `it` block -- and any other
|
180
|
+
blocks with per-example semantics -- such as a `before(:example)` hook -- are
|
181
|
+
evaluated in the context of
|
182
|
+
an _instance_ of the example group class to which the example belongs.
|
183
|
+
Examples are _not_ executed when the spec file is loaded; instead,
|
184
|
+
RSpec waits to run any examples until all spec files have been loaded,
|
185
|
+
at which point it can apply filtering, randomization, etc.
|
186
|
+
|
187
|
+
To make this more concrete, consider this code snippet:
|
188
|
+
|
189
|
+
``` ruby
|
190
|
+
RSpec.describe "Using an array as a stack" do
|
191
|
+
def build_stack
|
192
|
+
[]
|
193
|
+
end
|
194
|
+
|
195
|
+
before(:example) do
|
196
|
+
@stack = build_stack
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'is initially empty' do
|
200
|
+
expect(@stack).to be_empty
|
201
|
+
end
|
202
|
+
|
203
|
+
context "after an item has been pushed" do
|
204
|
+
before(:example) do
|
205
|
+
@stack.push :item
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'allows the pushed item to be popped' do
|
209
|
+
expect(@stack.pop).to eq(:item)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
Under the covers, this is (roughly) equivalent to:
|
216
|
+
|
217
|
+
``` ruby
|
218
|
+
class UsingAnArrayAsAStack < RSpec::Core::ExampleGroup
|
219
|
+
def build_stack
|
220
|
+
[]
|
221
|
+
end
|
222
|
+
|
223
|
+
def before_example_1
|
224
|
+
@stack = build_stack
|
225
|
+
end
|
226
|
+
|
227
|
+
def it_is_initially_empty
|
228
|
+
expect(@stack).to be_empty
|
229
|
+
end
|
230
|
+
|
231
|
+
class AfterAnItemHasBeenPushed < self
|
232
|
+
def before_example_2
|
233
|
+
@stack.push :item
|
234
|
+
end
|
235
|
+
|
236
|
+
def it_allows_the_pushed_item_to_be_popped
|
237
|
+
expect(@stack.pop).to eq(:item)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
```
|
242
|
+
|
243
|
+
To run these examples, RSpec would (roughly) do the following:
|
244
|
+
|
245
|
+
``` ruby
|
246
|
+
example_1 = UsingAnArrayAsAStack.new
|
247
|
+
example_1.before_example_1
|
248
|
+
example_1.it_is_initially_empty
|
249
|
+
|
250
|
+
example_2 = UsingAnArrayAsAStack::AfterAnItemHasBeenPushed.new
|
251
|
+
example_2.before_example_1
|
252
|
+
example_2.before_example_2
|
253
|
+
example_2.it_allows_the_pushed_item_to_be_popped
|
254
|
+
```
|
255
|
+
|
256
|
+
## The `rspec` Command
|
154
257
|
|
155
258
|
When you install the rspec-core gem, it installs the `rspec` executable,
|
156
|
-
which you'll use to run rspec. The `rspec` comes with many useful
|
259
|
+
which you'll use to run rspec. The `rspec` command comes with many useful
|
260
|
+
options.
|
157
261
|
Run `rspec --help` to see the complete list.
|
158
262
|
|
159
|
-
##
|
263
|
+
## Store Command Line Options `.rspec`
|
160
264
|
|
161
265
|
You can store command line options in a `.rspec` file in the project's root
|
162
266
|
directory, and the `rspec` command will read them as though you typed them on
|
163
267
|
the command line.
|
164
268
|
|
165
|
-
##
|
166
|
-
|
167
|
-
rspec-core ships with an Autotest extension, which is loaded automatically if
|
168
|
-
there is a `.rspec` file in the project's root directory.
|
169
|
-
|
170
|
-
## get started
|
269
|
+
## Get Started
|
171
270
|
|
172
271
|
Start with a simple example of behavior you expect from your system. Do
|
173
272
|
this before you write any implementation code:
|
174
273
|
|
175
274
|
```ruby
|
176
275
|
# in spec/calculator_spec.rb
|
177
|
-
describe Calculator do
|
178
|
-
|
179
|
-
|
276
|
+
RSpec.describe Calculator do
|
277
|
+
describe '#add' do
|
278
|
+
it 'returns the sum of its arguments' do
|
279
|
+
expect(Calculator.new.add(1, 2)).to eq(3)
|
280
|
+
end
|
180
281
|
end
|
181
282
|
end
|
182
283
|
```
|
@@ -188,13 +289,12 @@ $ rspec spec/calculator_spec.rb
|
|
188
289
|
./spec/calculator_spec.rb:1: uninitialized constant Calculator
|
189
290
|
```
|
190
291
|
|
191
|
-
|
292
|
+
Address the failure by defining a skeleton of the `Calculator` class:
|
192
293
|
|
193
294
|
```ruby
|
194
295
|
# in lib/calculator.rb
|
195
296
|
class Calculator
|
196
|
-
def add(a,b)
|
197
|
-
a + b
|
297
|
+
def add(a, b)
|
198
298
|
end
|
199
299
|
end
|
200
300
|
```
|
@@ -207,6 +307,39 @@ Be sure to require the implementation file in the spec:
|
|
207
307
|
require "calculator"
|
208
308
|
```
|
209
309
|
|
310
|
+
Now run the spec again, and watch the expectation fail:
|
311
|
+
|
312
|
+
```
|
313
|
+
$ rspec spec/calculator_spec.rb
|
314
|
+
F
|
315
|
+
|
316
|
+
Failures:
|
317
|
+
|
318
|
+
1) Calculator#add returns the sum of its arguments
|
319
|
+
Failure/Error: expect(Calculator.new.add(1, 2)).to eq(3)
|
320
|
+
|
321
|
+
expected: 3
|
322
|
+
got: nil
|
323
|
+
|
324
|
+
(compared using ==)
|
325
|
+
# ./spec/calcalator_spec.rb:6:in `block (3 levels) in <top (required)>'
|
326
|
+
|
327
|
+
Finished in 0.00131 seconds (files took 0.10968 seconds to load)
|
328
|
+
1 example, 1 failure
|
329
|
+
|
330
|
+
Failed examples:
|
331
|
+
|
332
|
+
rspec ./spec/calcalator_spec.rb:5 # Calculator#add returns the sum of its arguments
|
333
|
+
```
|
334
|
+
|
335
|
+
Implement the simplest solution, by changing the definition of `Calculator#add` to:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
def add(a, b)
|
339
|
+
a + b
|
340
|
+
end
|
341
|
+
```
|
342
|
+
|
210
343
|
Now run the spec again, and watch it pass:
|
211
344
|
|
212
345
|
```
|
@@ -221,15 +354,31 @@ Use the `documentation` formatter to see the resulting spec:
|
|
221
354
|
|
222
355
|
```
|
223
356
|
$ rspec spec/calculator_spec.rb --format doc
|
224
|
-
Calculator
|
225
|
-
|
357
|
+
Calculator
|
358
|
+
#add
|
359
|
+
returns the sum of its arguments
|
226
360
|
|
227
361
|
Finished in 0.000379 seconds
|
228
362
|
1 example, 0 failures
|
229
363
|
```
|
230
364
|
|
365
|
+
## Contributing
|
366
|
+
|
367
|
+
Once you've set up the environment, you'll need to cd into the working
|
368
|
+
directory of whichever repo you want to work in. From there you can run the
|
369
|
+
specs and cucumber features, and make patches.
|
370
|
+
|
371
|
+
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You
|
372
|
+
can treat each RSpec repo as an independent project.
|
373
|
+
|
374
|
+
* [Build details](BUILD_DETAIL.md)
|
375
|
+
* [Code of Conduct](CODE_OF_CONDUCT.md)
|
376
|
+
* [Detailed contributing guide](CONTRIBUTING.md)
|
377
|
+
* [Development setup guide](DEVELOPMENT.md)
|
378
|
+
|
231
379
|
## Also see
|
232
380
|
|
233
|
-
* [
|
234
|
-
* [
|
235
|
-
* [
|
381
|
+
* [https://github.com/rspec/rspec](https://github.com/rspec/rspec)
|
382
|
+
* [https://github.com/rspec/rspec-expectations](https://github.com/rspec/rspec-expectations)
|
383
|
+
* [https://github.com/rspec/rspec-mocks](https://github.com/rspec/rspec-mocks)
|
384
|
+
* [https://github.com/rspec/rspec-rails](https://github.com/rspec/rspec-rails)
|
data/exe/rspec
CHANGED
@@ -1,25 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
rescue LoadError
|
6
|
-
$stderr.puts <<-EOS
|
7
|
-
#{'*'*50}
|
8
|
-
Could not find 'rspec/autorun'
|
9
|
-
|
10
|
-
This may happen if you're using rubygems as your package manager, but it is not
|
11
|
-
being required through some mechanism before executing the rspec command.
|
12
|
-
|
13
|
-
You may need to do one of the following in your shell:
|
14
|
-
|
15
|
-
# for bash/zsh
|
16
|
-
export RUBYOPT=rubygems
|
17
|
-
|
18
|
-
# for csh, etc.
|
19
|
-
set RUBYOPT=rubygems
|
20
|
-
|
21
|
-
For background, please see http://gist.github.com/54177.
|
22
|
-
#{'*'*50}
|
23
|
-
EOS
|
24
|
-
exit(1)
|
25
|
-
end
|
3
|
+
require 'rspec/core'
|
4
|
+
RSpec::Core::Runner.invoke
|
data/lib/rspec/autorun.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
# @private
|
4
|
+
class BacktraceFormatter
|
5
|
+
# @private
|
6
|
+
attr_accessor :exclusion_patterns, :inclusion_patterns
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@full_backtrace = false
|
10
|
+
|
11
|
+
patterns = %w[ /lib\d*/ruby/ bin/ exe/rspec /lib/bundler/ /exe/bundle: ]
|
12
|
+
patterns << "org/jruby/" if RUBY_PLATFORM == 'java'
|
13
|
+
patterns.map! { |s| Regexp.new(s.gsub("/", File::SEPARATOR)) }
|
14
|
+
|
15
|
+
@exclusion_patterns = [Regexp.union(RSpec::CallerFilter::IGNORE_REGEX, *patterns)]
|
16
|
+
@inclusion_patterns = []
|
17
|
+
|
18
|
+
return unless matches?(@exclusion_patterns, File.join(Dir.getwd, "lib", "foo.rb:13"))
|
19
|
+
inclusion_patterns << Regexp.new(Dir.getwd)
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_writer :full_backtrace
|
23
|
+
|
24
|
+
def full_backtrace?
|
25
|
+
@full_backtrace || exclusion_patterns.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_gem(gem_name)
|
29
|
+
sep = File::SEPARATOR
|
30
|
+
exclusion_patterns << /#{sep}#{gem_name}(-[^#{sep}]+)?#{sep}/
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_backtrace(backtrace, options={})
|
34
|
+
return [] unless backtrace
|
35
|
+
return backtrace if options[:full_backtrace] || backtrace.empty?
|
36
|
+
|
37
|
+
backtrace.map { |l| backtrace_line(l) }.compact.
|
38
|
+
tap do |filtered|
|
39
|
+
if filtered.empty?
|
40
|
+
filtered.concat backtrace
|
41
|
+
filtered << ""
|
42
|
+
filtered << " Showing full backtrace because every line was filtered out."
|
43
|
+
filtered << " See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
|
44
|
+
filtered << " RSpec::Configuration#backtrace_inclusion_patterns for more information."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def backtrace_line(line)
|
50
|
+
Metadata.relative_path(line) unless exclude?(line)
|
51
|
+
end
|
52
|
+
|
53
|
+
def exclude?(line)
|
54
|
+
return false if @full_backtrace
|
55
|
+
matches?(exclusion_patterns, line) && !matches?(inclusion_patterns, line)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def matches?(patterns, line)
|
61
|
+
patterns.any? { |p| line =~ p }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
RSpec::Support.require_rspec_core "bisect/shell_command"
|
2
|
+
RSpec::Support.require_rspec_core "bisect/example_minimizer"
|
3
|
+
RSpec::Support.require_rspec_core "bisect/utilities"
|
4
|
+
RSpec::Support.require_rspec_core "formatters/bisect_progress_formatter"
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module Core
|
8
|
+
module Bisect
|
9
|
+
# The main entry point into the bisect logic. Coordinates among:
|
10
|
+
# - Bisect::ShellCommand: Generates shell commands to run spec subsets
|
11
|
+
# - Bisect::ExampleMinimizer: Contains the core bisect logic.
|
12
|
+
# - A bisect runner: runs a set of examples and returns the results.
|
13
|
+
# - A bisect formatter: provides progress updates to the user.
|
14
|
+
# @private
|
15
|
+
class Coordinator
|
16
|
+
def self.bisect_with(spec_runner, original_cli_args, formatter)
|
17
|
+
new(spec_runner, original_cli_args, formatter).bisect
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(spec_runner, original_cli_args, formatter)
|
21
|
+
@spec_runner = spec_runner
|
22
|
+
@shell_command = ShellCommand.new(original_cli_args)
|
23
|
+
@notifier = Bisect::Notifier.new(formatter)
|
24
|
+
end
|
25
|
+
|
26
|
+
def bisect
|
27
|
+
repro = start_bisect_runner do |runner|
|
28
|
+
minimizer = ExampleMinimizer.new(@shell_command, runner, @notifier)
|
29
|
+
|
30
|
+
gracefully_abort_on_sigint(minimizer)
|
31
|
+
minimizer.find_minimal_repro
|
32
|
+
minimizer.repro_command_for_currently_needed_ids
|
33
|
+
end
|
34
|
+
|
35
|
+
@notifier.publish(:bisect_repro_command, :repro => repro)
|
36
|
+
|
37
|
+
true
|
38
|
+
rescue BisectFailedError => e
|
39
|
+
@notifier.publish(:bisect_failed, :failure_explanation => e.message)
|
40
|
+
false
|
41
|
+
ensure
|
42
|
+
@notifier.publish(:close)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def start_bisect_runner(&block)
|
48
|
+
klass = @spec_runner.configuration.bisect_runner_class
|
49
|
+
klass.start(@shell_command, @spec_runner, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
def gracefully_abort_on_sigint(minimizer)
|
53
|
+
trap('INT') do
|
54
|
+
repro = minimizer.repro_command_for_currently_needed_ids
|
55
|
+
@notifier.publish(:bisect_aborted, :repro => repro)
|
56
|
+
exit(1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|