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,31 +0,0 @@
|
|
1
|
-
Feature: Configurable colors
|
2
|
-
|
3
|
-
RSpec allows you to configure the terminal colors used in the text formatters.
|
4
|
-
|
5
|
-
* `failure_color`: Color used when tests fail (default: `:red`)
|
6
|
-
* `success_color`: Color used when tests pass (default: `:green`)
|
7
|
-
* `pending_color`: Color used when tests are pending (default: `:yellow`)
|
8
|
-
* `fixed_color`: Color used when a pending block inside an example passes, but was expected to fail (default: `:blue`)
|
9
|
-
* `detail_color`: Color used for miscellaneous test details (default: `:cyan`)
|
10
|
-
|
11
|
-
Colors are normally specified as symbols. Options are `:black`, `:red`,
|
12
|
-
`:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, and `:white`.
|
13
|
-
|
14
|
-
@ansi
|
15
|
-
Scenario: Customizing the failure color
|
16
|
-
Given a file named "custom_failure_color_spec.rb" with:
|
17
|
-
"""ruby
|
18
|
-
RSpec.configure do |config|
|
19
|
-
config.failure_color = :magenta
|
20
|
-
config.tty = true
|
21
|
-
config.color = true
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "failure" do
|
25
|
-
it "fails and uses the custom color" do
|
26
|
-
expect(2).to eq(4)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
"""
|
30
|
-
When I run `rspec custom_failure_color_spec.rb --format progress`
|
31
|
-
Then the failing example is printed in magenta
|
@@ -1,68 +0,0 @@
|
|
1
|
-
Feature: custom formatters
|
2
|
-
|
3
|
-
RSpec ships with general purpose output formatters. You can tell RSpec which
|
4
|
-
one to use using the [`--format` command line
|
5
|
-
option]('../command_line/format_option').
|
6
|
-
|
7
|
-
When RSpec's built-in output formatters don't, however, give you everything
|
8
|
-
you need, you can write your own custom formatter and tell RSpec to use that
|
9
|
-
one instead. The simplest way is to subclass RSpec's `BaseTextFormatter`,
|
10
|
-
and then override just the methods that you want to modify.
|
11
|
-
|
12
|
-
Scenario: custom formatter
|
13
|
-
Given a file named "custom_formatter.rb" with:
|
14
|
-
"""ruby
|
15
|
-
require "rspec/core/formatters/base_text_formatter"
|
16
|
-
|
17
|
-
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
18
|
-
|
19
|
-
# This registers the notifications this formatter supports, and tells
|
20
|
-
# us that this was written against the RSpec 3.x formatter API.
|
21
|
-
RSpec::Core::Formatters.register self, :example_started
|
22
|
-
|
23
|
-
def initialize(output)
|
24
|
-
super(output)
|
25
|
-
end
|
26
|
-
|
27
|
-
def example_started(notification)
|
28
|
-
output << "example: " << notification.example.description
|
29
|
-
end
|
30
|
-
end
|
31
|
-
"""
|
32
|
-
And a file named "example_spec.rb" with:
|
33
|
-
"""ruby
|
34
|
-
describe "my group" do
|
35
|
-
specify "my example" do
|
36
|
-
end
|
37
|
-
end
|
38
|
-
"""
|
39
|
-
When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
|
40
|
-
Then the output should contain "example: my example"
|
41
|
-
And the exit status should be 0
|
42
|
-
|
43
|
-
Scenario: a legacy custom formatter
|
44
|
-
Given a file named "custom_formatter.rb" with:
|
45
|
-
"""ruby
|
46
|
-
require "rspec/core/formatters/base_text_formatter"
|
47
|
-
|
48
|
-
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
49
|
-
def initialize(output)
|
50
|
-
super(output)
|
51
|
-
end
|
52
|
-
|
53
|
-
def example_started(proxy)
|
54
|
-
output << "example: " << proxy.description
|
55
|
-
end
|
56
|
-
end
|
57
|
-
"""
|
58
|
-
And a file named "example_spec.rb" with:
|
59
|
-
"""ruby
|
60
|
-
describe "my group" do
|
61
|
-
specify "my example" do
|
62
|
-
end
|
63
|
-
end
|
64
|
-
"""
|
65
|
-
When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
|
66
|
-
Then the output should contain "example: my example"
|
67
|
-
And the output should contain "The CustomFormatter formatter uses the deprecated formatter interface."
|
68
|
-
And the exit status should be 0
|
@@ -1,30 +0,0 @@
|
|
1
|
-
Feature: JSON formatter
|
2
|
-
|
3
|
-
Scenario: Formatting example names for retry
|
4
|
-
Given a file named "various_spec.rb" with:
|
5
|
-
"""ruby
|
6
|
-
describe "Various" do
|
7
|
-
it "fails" do
|
8
|
-
expect("fail").to eq("succeed")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "succeeds" do
|
12
|
-
expect("succeed").to eq("succeed")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "pends"
|
16
|
-
end
|
17
|
-
"""
|
18
|
-
When I run `rspec various_spec.rb --format j`
|
19
|
-
Then the output should contain all of these:
|
20
|
-
|"summary_line":"3 examples, 1 failure, 1 pending"|
|
21
|
-
|"examples":[ |
|
22
|
-
|"description":"fails" |
|
23
|
-
|"full_description":"Various fails" |
|
24
|
-
|"status":"failed" |
|
25
|
-
|"file_path":"./various_spec.rb" |
|
26
|
-
|"line_number":2 |
|
27
|
-
|"exception":{ |
|
28
|
-
|"class":"RSpec::Expectations::ExpectationNotMetError"|
|
29
|
-
|
30
|
-
And the exit status should be 1
|
@@ -1,95 +0,0 @@
|
|
1
|
-
Feature: Regression tests for legacy custom formatters
|
2
|
-
|
3
|
-
Background:
|
4
|
-
Given a file named ".rspec" with:
|
5
|
-
"""
|
6
|
-
--require spec_helper
|
7
|
-
"""
|
8
|
-
And a file named "spec/spec_helper.rb" with:
|
9
|
-
"""
|
10
|
-
RSpec.configure do |rspec|
|
11
|
-
rspec.after(:suite) do
|
12
|
-
puts rspec.formatters.map(&:class).inspect
|
13
|
-
end
|
14
|
-
end
|
15
|
-
"""
|
16
|
-
And a file named "spec/passing_and_failing_spec.rb" with:
|
17
|
-
"""ruby
|
18
|
-
RSpec.describe "Some examples" do
|
19
|
-
it "passes" do
|
20
|
-
expect(1).to eq(1)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "fails" do
|
24
|
-
expect(1).to eq(2)
|
25
|
-
end
|
26
|
-
|
27
|
-
context "nested" do
|
28
|
-
it "passes" do
|
29
|
-
expect(1).to eq(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "fails" do
|
33
|
-
expect(1).to eq(2)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
"""
|
38
|
-
And a file named "spec/pending_spec.rb" with:
|
39
|
-
"""ruby
|
40
|
-
RSpec.describe "Some pending examples" do
|
41
|
-
context "pending" do
|
42
|
-
it "is reported as pending" do
|
43
|
-
pending; expect(1).to eq(2)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "is reported as failing" do
|
47
|
-
pending; expect(1).to eq(1)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
"""
|
52
|
-
|
53
|
-
Scenario: Use fuubar formatter
|
54
|
-
When I run `rspec --format Fuubar`
|
55
|
-
Then the output should contain "Progress: |============"
|
56
|
-
And the output should contain "6 examples, 3 failures, 1 pending"
|
57
|
-
And the output should contain "The Fuubar formatter uses the deprecated formatter interface"
|
58
|
-
But the output should not contain any error backtraces
|
59
|
-
And the output should not contain "ProgressFormatter"
|
60
|
-
|
61
|
-
Scenario: Use rspec-instafail formatter
|
62
|
-
When I run `rspec --format RSpec::Instafail`
|
63
|
-
Then the output should contain "6 examples, 3 failures, 1 pending"
|
64
|
-
And the output should contain "The RSpec::Instafail formatter uses the deprecated formatter interface"
|
65
|
-
But the output should not contain any error backtraces
|
66
|
-
And the output should not contain "ProgressFormatter"
|
67
|
-
|
68
|
-
Scenario: Use rspec-extra-formatters JUnit formatter
|
69
|
-
When I run `rspec --require rspec-extra-formatters --format JUnitFormatter`
|
70
|
-
Then the output should contain:
|
71
|
-
"""
|
72
|
-
<testsuite errors="0" failures="3" skipped="1" tests="6"
|
73
|
-
"""
|
74
|
-
And the output should contain "The JUnitFormatter formatter uses the deprecated formatter interface"
|
75
|
-
But the output should not contain any error backtraces
|
76
|
-
And the output should not contain "ProgressFormatter"
|
77
|
-
|
78
|
-
@wip @announce
|
79
|
-
Scenario: Use rspec-extra-formatters Tap formatter
|
80
|
-
When I run `rspec --require rspec-extra-formatters --format TapFormatter`
|
81
|
-
Then the output should contain "TAP version 13"
|
82
|
-
And the output should contain "The TapFormatter formatter uses the deprecated formatter interface"
|
83
|
-
But the output should not contain any error backtraces
|
84
|
-
And the output should not contain "ProgressFormatter"
|
85
|
-
|
86
|
-
@wip @announce
|
87
|
-
Scenario: Use rspec-spinner formatter
|
88
|
-
When I run `rspec --require rspec_spinner --format RspecSpinner::Spinner`
|
89
|
-
Then the output should contain "TBD"
|
90
|
-
|
91
|
-
@wip @announce
|
92
|
-
Scenario: Use nyancat formatter
|
93
|
-
When I run `rspec --format NyanCatFormatter`
|
94
|
-
Then the output should contain "TBD"
|
95
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
Feature: text formatter
|
2
|
-
|
3
|
-
In order to easily see the result of running my specs
|
4
|
-
As an RSpec user
|
5
|
-
I want clear, concise, well-formatted output
|
6
|
-
|
7
|
-
Scenario: Backtrace formatting for failing specs in multiple files
|
8
|
-
Given a file named "string_spec.rb" with:
|
9
|
-
"""ruby
|
10
|
-
describe String do
|
11
|
-
it "has a failing example" do
|
12
|
-
expect("foo".reverse).to eq("ofo")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
"""
|
16
|
-
And a file named "integer_spec.rb" with:
|
17
|
-
"""ruby
|
18
|
-
describe Integer do
|
19
|
-
it "has a failing example" do
|
20
|
-
expect(7 + 5).to eq(11)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
"""
|
24
|
-
When I run `rspec integer_spec.rb string_spec.rb`
|
25
|
-
Then the backtrace-normalized output should contain:
|
26
|
-
"""
|
27
|
-
1) Integer has a failing example
|
28
|
-
Failure/Error: expect(7 + 5).to eq(11)
|
29
|
-
|
30
|
-
expected: 11
|
31
|
-
got: 12
|
32
|
-
|
33
|
-
(compared using ==)
|
34
|
-
# ./integer_spec.rb:3
|
35
|
-
"""
|
36
|
-
And the backtrace-normalized output should contain:
|
37
|
-
"""
|
38
|
-
2) String has a failing example
|
39
|
-
Failure/Error: expect("foo".reverse).to eq("ofo")
|
40
|
-
|
41
|
-
expected: "ofo"
|
42
|
-
got: "oof"
|
43
|
-
|
44
|
-
(compared using ==)
|
45
|
-
# ./string_spec.rb:3
|
46
|
-
"""
|
@@ -1,40 +0,0 @@
|
|
1
|
-
Feature: arbitrary helper methods
|
2
|
-
|
3
|
-
You can define methods in any example group using Ruby's `def` keyword or
|
4
|
-
`define_method` method. These _helper_ methods are exposed to examples in the
|
5
|
-
group in which they are defined and groups nested within that group, but not
|
6
|
-
parent or sibling groups.
|
7
|
-
|
8
|
-
Scenario: use a method defined in the same group
|
9
|
-
Given a file named "example_spec.rb" with:
|
10
|
-
"""ruby
|
11
|
-
describe "an example" do
|
12
|
-
def help
|
13
|
-
:available
|
14
|
-
end
|
15
|
-
|
16
|
-
it "has access to methods defined in its group" do
|
17
|
-
expect(help).to be(:available)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
"""
|
21
|
-
When I run `rspec example_spec.rb`
|
22
|
-
Then the examples should all pass
|
23
|
-
|
24
|
-
Scenario: use a method defined in a parent group
|
25
|
-
Given a file named "example_spec.rb" with:
|
26
|
-
"""ruby
|
27
|
-
describe "an example" do
|
28
|
-
def help
|
29
|
-
:available
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "in a nested group" do
|
33
|
-
it "has access to methods defined in its parent group" do
|
34
|
-
expect(help).to be(:available)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
"""
|
39
|
-
When I run `rspec example_spec.rb`
|
40
|
-
Then the examples should all pass
|
@@ -1,50 +0,0 @@
|
|
1
|
-
Feature: let and let!
|
2
|
-
|
3
|
-
Use `let` to define a memoized helper method. The value will be cached
|
4
|
-
across multiple calls in the same example but not across examples.
|
5
|
-
|
6
|
-
Note that `let` is lazy-evaluated: it is not evaluated until the first time
|
7
|
-
the method it defines is invoked. You can use `let!` to force the method's
|
8
|
-
invocation before each example.
|
9
|
-
|
10
|
-
Scenario: use let to define memoized helper method
|
11
|
-
Given a file named "let_spec.rb" with:
|
12
|
-
"""ruby
|
13
|
-
$count = 0
|
14
|
-
describe "let" do
|
15
|
-
let(:count) { $count += 1 }
|
16
|
-
|
17
|
-
it "memoizes the value" do
|
18
|
-
expect(count).to eq(1)
|
19
|
-
expect(count).to eq(1)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "is not cached across examples" do
|
23
|
-
expect(count).to eq(2)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
"""
|
27
|
-
When I run `rspec let_spec.rb`
|
28
|
-
Then the examples should all pass
|
29
|
-
|
30
|
-
Scenario: use let! to define a memoized helper method that is called in a before hook
|
31
|
-
Given a file named "let_bang_spec.rb" with:
|
32
|
-
"""ruby
|
33
|
-
$count = 0
|
34
|
-
describe "let!" do
|
35
|
-
invocation_order = []
|
36
|
-
|
37
|
-
let!(:count) do
|
38
|
-
invocation_order << :let!
|
39
|
-
$count += 1
|
40
|
-
end
|
41
|
-
|
42
|
-
it "calls the helper method in a before hook" do
|
43
|
-
invocation_order << :example
|
44
|
-
expect(invocation_order).to eq([:let!, :example])
|
45
|
-
expect(count).to eq(1)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
"""
|
49
|
-
When I run `rspec let_bang_spec.rb`
|
50
|
-
Then the examples should all pass
|
@@ -1,146 +0,0 @@
|
|
1
|
-
Feature: Define helper methods in a module
|
2
|
-
|
3
|
-
You can define helper methods in a module and include it in
|
4
|
-
your example groups using the `config.include` configuration
|
5
|
-
option. `config.extend` can be used to extend the module onto
|
6
|
-
your example groups so that the methods in the module are available
|
7
|
-
in the example groups themselves (but not in the actual examples).
|
8
|
-
|
9
|
-
You can also include or extend the module onto only certain example
|
10
|
-
groups by passing a metadata hash as the last argument. Only groups
|
11
|
-
that match the given metadata will include or extend the module. You
|
12
|
-
can also specify metadata using only symbols.
|
13
|
-
|
14
|
-
Background:
|
15
|
-
Given a file named "helpers.rb" with:
|
16
|
-
"""ruby
|
17
|
-
module Helpers
|
18
|
-
def help
|
19
|
-
:available
|
20
|
-
end
|
21
|
-
end
|
22
|
-
"""
|
23
|
-
|
24
|
-
Scenario: include a module in all example groups
|
25
|
-
Given a file named "include_module_spec.rb" with:
|
26
|
-
"""ruby
|
27
|
-
require './helpers'
|
28
|
-
|
29
|
-
RSpec.configure do |c|
|
30
|
-
c.include Helpers
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "an example group" do
|
34
|
-
it "has access to the helper methods defined in the module" do
|
35
|
-
expect(help).to be(:available)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
"""
|
39
|
-
When I run `rspec include_module_spec.rb`
|
40
|
-
Then the examples should all pass
|
41
|
-
|
42
|
-
Scenario: extend a module in all example groups
|
43
|
-
Given a file named "extend_module_spec.rb" with:
|
44
|
-
"""ruby
|
45
|
-
require './helpers'
|
46
|
-
|
47
|
-
RSpec.configure do |c|
|
48
|
-
c.extend Helpers
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "an example group" do
|
52
|
-
puts "Help is #{help}"
|
53
|
-
|
54
|
-
it "does not have access to the helper methods defined in the module" do
|
55
|
-
expect { help }.to raise_error(NameError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
"""
|
59
|
-
When I run `rspec extend_module_spec.rb`
|
60
|
-
Then the examples should all pass
|
61
|
-
And the output should contain "Help is available"
|
62
|
-
|
63
|
-
Scenario: include a module in only some example groups
|
64
|
-
Given a file named "include_module_in_some_groups_spec.rb" with:
|
65
|
-
"""ruby
|
66
|
-
require './helpers'
|
67
|
-
|
68
|
-
RSpec.configure do |c|
|
69
|
-
c.include Helpers, :foo => :bar
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "an example group with matching metadata", :foo => :bar do
|
73
|
-
it "has access to the helper methods defined in the module" do
|
74
|
-
expect(help).to be(:available)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "an example group without matching metadata" do
|
79
|
-
it "does not have access to the helper methods defined in the module" do
|
80
|
-
expect { help }.to raise_error(NameError)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
"""
|
84
|
-
When I run `rspec include_module_in_some_groups_spec.rb`
|
85
|
-
Then the examples should all pass
|
86
|
-
|
87
|
-
Scenario: extend a module in only some example groups
|
88
|
-
Given a file named "extend_module_in_only_some_groups_spec.rb" with:
|
89
|
-
"""ruby
|
90
|
-
require './helpers'
|
91
|
-
|
92
|
-
RSpec.configure do |c|
|
93
|
-
c.extend Helpers, :foo => :bar
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "an example group with matching metadata", :foo => :bar do
|
97
|
-
puts "In a matching group, help is #{help}"
|
98
|
-
|
99
|
-
it "does not have access to the helper methods defined in the module" do
|
100
|
-
expect { help }.to raise_error(NameError)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "an example group without matching metadata" do
|
105
|
-
puts "In a non-matching group, help is #{help rescue 'not available'}"
|
106
|
-
|
107
|
-
it "does not have access to the helper methods defined in the module" do
|
108
|
-
expect { help }.to raise_error(NameError)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
"""
|
112
|
-
When I run `rspec extend_module_in_only_some_groups_spec.rb`
|
113
|
-
Then the examples should all pass
|
114
|
-
And the output should contain "In a matching group, help is available"
|
115
|
-
And the output should contain "In a non-matching group, help is not available"
|
116
|
-
|
117
|
-
Scenario: use symbols as metadata
|
118
|
-
Given a file named "symbols_as_metadata_spec.rb" with:
|
119
|
-
"""ruby
|
120
|
-
require './helpers'
|
121
|
-
|
122
|
-
RSpec.configure do |c|
|
123
|
-
c.include Helpers, :include_helpers
|
124
|
-
c.extend Helpers, :extend_helpers
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "an example group with matching include metadata", :include_helpers do
|
128
|
-
puts "In a group not matching the extend filter, help is #{help rescue 'not available'}"
|
129
|
-
|
130
|
-
it "has access to the helper methods defined in the module" do
|
131
|
-
expect(help).to be(:available)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "an example group with matching extend metadata", :extend_helpers do
|
136
|
-
puts "In a group matching the extend filter, help is #{help}"
|
137
|
-
|
138
|
-
it "does not have access to the helper methods defined in the module" do
|
139
|
-
expect { help }.to raise_error(NameError)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
"""
|
143
|
-
When I run `rspec symbols_as_metadata_spec.rb`
|
144
|
-
Then the examples should all pass
|
145
|
-
And the output should contain "In a group not matching the extend filter, help is not available"
|
146
|
-
And the output should contain "In a group matching the extend filter, help is available"
|