rspec-core 2.5.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +7 -0
- data/Gemfile +12 -14
- data/README.md +4 -1
- data/Rakefile +29 -12
- data/cucumber.yml +1 -1
- data/features/.nav +15 -9
- data/features/Autotest.md +31 -7
- data/features/Changelog.md +46 -3
- data/features/Upgrade.md +35 -2
- data/features/command_line/README.md +22 -0
- data/features/command_line/configure.feature +2 -2
- data/features/command_line/example_name_option.feature +10 -10
- data/features/command_line/exit_status.feature +4 -4
- data/features/command_line/format_option.feature +4 -4
- data/features/command_line/line_number_appended_to_path.feature +11 -11
- data/features/command_line/line_number_option.feature +2 -2
- data/features/command_line/rake_task.feature +3 -3
- data/features/command_line/tag.feature +30 -14
- data/features/configuration/alias_example_to.feature +48 -0
- data/features/configuration/custom_settings.feature +3 -3
- data/features/configuration/fail_fast.feature +3 -3
- data/features/configuration/read_options_from_file.feature +4 -4
- data/features/example_groups/basic_structure.feature +11 -15
- data/features/example_groups/shared_context.feature +74 -0
- data/features/example_groups/shared_example_group.feature +21 -17
- data/features/expectation_framework_integration/configure_expectation_framework.feature +15 -4
- data/features/filtering/exclusion_filters.feature +28 -4
- data/features/filtering/{implicit_filters.feature → if_and_unless.feature} +9 -7
- data/features/filtering/inclusion_filters.feature +26 -3
- data/features/filtering/run_all_when_everything_filtered.feature +2 -2
- data/features/formatters/custom_formatter.feature +1 -1
- data/features/formatters/text_formatter.feature +43 -0
- data/features/helper_methods/arbitrary_methods.feature +2 -2
- data/features/helper_methods/let.feature +2 -2
- data/features/helper_methods/modules.feature +149 -0
- data/features/hooks/around_hooks.feature +18 -11
- data/features/hooks/before_and_after_hooks.feature +15 -19
- data/features/hooks/filtering.feature +160 -124
- data/features/metadata/current_example.feature +17 -0
- data/features/metadata/described_class.feature +2 -2
- data/features/metadata/user_defined.feature +111 -0
- data/features/mock_framework_integration/use_any_framework.feature +1 -1
- data/features/mock_framework_integration/use_flexmock.feature +83 -10
- data/features/mock_framework_integration/use_mocha.feature +84 -10
- data/features/mock_framework_integration/use_rr.feature +85 -10
- data/features/mock_framework_integration/use_rspec.feature +84 -10
- data/features/pending/pending_examples.feature +8 -8
- data/features/spec_files/arbitrary_file_suffix.feature +1 -1
- data/features/step_definitions/additional_cli_steps.rb +11 -1
- data/features/subject/attribute_of_subject.feature +24 -4
- data/features/subject/explicit_subject.feature +5 -5
- data/features/subject/implicit_receiver.feature +2 -2
- data/features/subject/implicit_subject.feature +2 -2
- data/features/support/env.rb +6 -1
- data/lib/rspec/core/backward_compatibility.rb +12 -2
- data/lib/rspec/core/command_line.rb +2 -5
- data/lib/rspec/core/configuration.rb +70 -38
- data/lib/rspec/core/configuration_options.rb +6 -23
- data/lib/rspec/core/drb_command_line.rb +5 -11
- data/lib/rspec/core/example.rb +29 -21
- data/lib/rspec/core/example_group.rb +40 -8
- data/lib/rspec/core/extensions/object.rb +0 -1
- data/lib/rspec/core/formatters/base_formatter.rb +6 -0
- data/lib/rspec/core/formatters/base_text_formatter.rb +1 -1
- data/lib/rspec/core/formatters/helpers.rb +0 -4
- data/lib/rspec/core/hooks.rb +14 -4
- data/lib/rspec/core/metadata.rb +1 -1
- data/lib/rspec/core/metadata_hash_builder.rb +93 -0
- data/lib/rspec/core/mocking/with_flexmock.rb +2 -0
- data/lib/rspec/core/mocking/with_mocha.rb +2 -0
- data/lib/rspec/core/mocking/with_rr.rb +2 -0
- data/lib/rspec/core/mocking/with_rspec.rb +3 -1
- data/lib/rspec/core/option_parser.rb +9 -2
- data/lib/rspec/core/pending.rb +10 -3
- data/lib/rspec/core/reporter.rb +2 -2
- data/lib/rspec/core/runner.rb +38 -13
- data/lib/rspec/core/shared_example_group.rb +18 -4
- data/lib/rspec/core/subject.rb +4 -6
- data/lib/rspec/core/version.rb +1 -1
- data/lib/rspec/core/world.rb +70 -18
- data/lib/rspec/core.rb +29 -0
- data/lib/rspec/monkey/spork/test_framework/rspec.rb +1 -0
- data/rspec-core.gemspec +3 -5
- data/spec/autotest/failed_results_re_spec.rb +2 -2
- data/spec/rspec/core/command_line_spec.rb +36 -2
- data/spec/rspec/core/configuration_spec.rb +150 -70
- data/spec/rspec/core/deprecations_spec.rb +21 -0
- data/spec/rspec/core/drb_command_line_spec.rb +21 -56
- data/spec/rspec/core/example_group_spec.rb +213 -56
- data/spec/rspec/core/example_spec.rb +110 -0
- data/spec/rspec/core/formatters/base_formatter_spec.rb +23 -2
- data/spec/rspec/core/formatters/base_text_formatter_spec.rb +9 -0
- data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
- data/spec/rspec/core/formatters/html_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/html_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/html_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -1
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.6.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +8 -10
- data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.1.html +5 -5
- data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +5 -5
- data/spec/rspec/core/hooks_spec.rb +86 -0
- data/spec/rspec/core/metadata_spec.rb +7 -7
- data/spec/rspec/core/option_parser_spec.rb +26 -15
- data/spec/rspec/core/pending_example_spec.rb +12 -51
- data/spec/rspec/core/reporter_spec.rb +19 -3
- data/spec/rspec/core/resources/formatter_specs.rb +7 -1
- data/spec/rspec/core/rspec_matchers_spec.rb +45 -0
- data/spec/rspec/core/runner_spec.rb +42 -10
- data/spec/rspec/core/shared_example_group_spec.rb +57 -21
- data/spec/rspec/core/subject_spec.rb +32 -11
- data/spec/rspec/core/world_spec.rb +147 -15
- data/spec/rspec/core_spec.rb +28 -0
- data/spec/spec_helper.rb +22 -2
- data/spec/support/matchers.rb +44 -13
- data/spec/support/shared_example_groups.rb +41 -0
- data/spec/support/spec_files.rb +44 -0
- data/spec.txt +1126 -0
- metadata +35 -16
- data/spec/ruby_forker.rb +0 -13
|
@@ -19,7 +19,8 @@ Feature: --tag option
|
|
|
19
19
|
"""
|
|
20
20
|
describe "group with tagged specs" do
|
|
21
21
|
it "example I'm working now", :focus => true do; end
|
|
22
|
-
it "special example", :type => 'special' do; end
|
|
22
|
+
it "special example with string", :type => 'special' do; end
|
|
23
|
+
it "special example with symbol", :type => :special do; end
|
|
23
24
|
it "slow example", :skip => true do; end
|
|
24
25
|
it "ordinary example", :speed => 'slow' do; end
|
|
25
26
|
it "untagged example" do; end
|
|
@@ -27,48 +28,63 @@ Feature: --tag option
|
|
|
27
28
|
"""
|
|
28
29
|
|
|
29
30
|
Scenario: filter examples with non-existent tag
|
|
30
|
-
When I run
|
|
31
|
+
When I run `rspec . --tag mytag`
|
|
31
32
|
And the examples should all pass
|
|
32
33
|
|
|
33
34
|
Scenario: filter examples with a simple tag
|
|
34
|
-
When I run
|
|
35
|
-
Then the output should contain "Run filtered
|
|
35
|
+
When I run `rspec . --tag focus`
|
|
36
|
+
Then the output should contain "Run filtered including {:focus=>true}"
|
|
36
37
|
And the examples should all pass
|
|
37
38
|
|
|
38
39
|
Scenario: filter examples with a simple tag and @
|
|
39
|
-
When I run
|
|
40
|
-
Then the output should contain "Run filtered
|
|
40
|
+
When I run `rspec . --tag @focus`
|
|
41
|
+
Then the output should contain "Run filtered including {:focus=>true}"
|
|
41
42
|
Then the examples should all pass
|
|
42
43
|
|
|
43
44
|
Scenario: filter examples with a name:value tag
|
|
44
|
-
When I run
|
|
45
|
+
When I run `rspec . --tag type:special`
|
|
45
46
|
Then the output should contain:
|
|
46
47
|
"""
|
|
47
|
-
Run filtered
|
|
48
|
+
Run filtered including {:type=>"special"}
|
|
48
49
|
"""
|
|
50
|
+
And the output should contain "2 examples"
|
|
49
51
|
And the examples should all pass
|
|
50
52
|
|
|
51
53
|
Scenario: filter examples with a name:value tag and @
|
|
52
|
-
When I run
|
|
54
|
+
When I run `rspec . --tag @type:special`
|
|
53
55
|
Then the output should contain:
|
|
54
56
|
"""
|
|
55
|
-
Run filtered
|
|
57
|
+
Run filtered including {:type=>"special"}
|
|
56
58
|
"""
|
|
57
59
|
And the examples should all pass
|
|
58
60
|
|
|
59
61
|
Scenario: exclude examples with a simple tag
|
|
60
|
-
When I run
|
|
62
|
+
When I run `rspec . --tag ~skip`
|
|
63
|
+
Then the output should contain "Run filtered excluding {:skip=>true}"
|
|
61
64
|
Then the examples should all pass
|
|
62
65
|
|
|
63
66
|
Scenario: exclude examples with a simple tag and @
|
|
64
|
-
When I run
|
|
67
|
+
When I run `rspec . --tag ~@skip`
|
|
68
|
+
Then the output should contain "Run filtered excluding {:skip=>true}"
|
|
65
69
|
Then the examples should all pass
|
|
66
70
|
|
|
67
71
|
Scenario: exclude examples with a name:value tag
|
|
68
|
-
When I run
|
|
72
|
+
When I run `rspec . --tag ~speed:slow`
|
|
73
|
+
Then the output should contain:
|
|
74
|
+
"""
|
|
75
|
+
Run filtered excluding {:speed=>"slow"}
|
|
76
|
+
"""
|
|
69
77
|
Then the examples should all pass
|
|
70
78
|
|
|
71
79
|
Scenario: exclude examples with a name:value tag and @
|
|
72
|
-
When I run
|
|
80
|
+
When I run `rspec . --tag ~@speed:slow`
|
|
81
|
+
Then the output should contain:
|
|
82
|
+
"""
|
|
83
|
+
Run filtered excluding {:speed=>"slow"}
|
|
84
|
+
"""
|
|
73
85
|
Then the examples should all pass
|
|
74
86
|
|
|
87
|
+
Scenario: filter examples with a simple tag, exclude examples with another tag
|
|
88
|
+
When I run `rspec . --tag focus --tag ~skip`
|
|
89
|
+
Then the output should contain "Run filtered including {:focus=>true}, excluding {:skip=>true}"
|
|
90
|
+
And the examples should all pass
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Feature: alias_example_to
|
|
2
|
+
|
|
3
|
+
Use `config.alias_example_to` to create new example group methods
|
|
4
|
+
that define examples with the configured metadata.
|
|
5
|
+
|
|
6
|
+
If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
|
|
7
|
+
to `true`, you can specify metadata using only symbols.
|
|
8
|
+
|
|
9
|
+
Scenario: Use alias_example_to to define focused example
|
|
10
|
+
Given a file named "alias_example_to_spec.rb" with:
|
|
11
|
+
"""
|
|
12
|
+
RSpec.configure do |c|
|
|
13
|
+
c.alias_example_to :fit, :focused => true
|
|
14
|
+
c.filter_run :focused => true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "an example group" do
|
|
18
|
+
it "does one thing" do
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
fit "does another thing" do
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
"""
|
|
25
|
+
When I run `rspec alias_example_to_spec.rb --format doc`
|
|
26
|
+
Then the output should contain "does another thing"
|
|
27
|
+
And the output should not contain "does one thing"
|
|
28
|
+
|
|
29
|
+
Scenario: use symbols as metadata
|
|
30
|
+
Given a file named "use_symbols_as_metadata_spec.rb" with:
|
|
31
|
+
"""
|
|
32
|
+
RSpec.configure do |c|
|
|
33
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
|
34
|
+
c.alias_example_to :fit, :focused
|
|
35
|
+
c.filter_run :focused
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "an example group" do
|
|
39
|
+
it "does one thing" do
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
fit "does another thing" do
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
"""
|
|
46
|
+
When I run `rspec use_symbols_as_metadata_spec.rb --format doc`
|
|
47
|
+
Then the output should contain "does another thing"
|
|
48
|
+
And the output should not contain "does one thing"
|
|
@@ -29,7 +29,7 @@ Feature: custom settings
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
"""
|
|
32
|
-
When I run
|
|
32
|
+
When I run `rspec ./additional_setting_spec.rb`
|
|
33
33
|
Then the examples should all pass
|
|
34
34
|
|
|
35
35
|
Scenario: default to true
|
|
@@ -55,7 +55,7 @@ Feature: custom settings
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
"""
|
|
58
|
-
When I run
|
|
58
|
+
When I run `rspec ./additional_setting_spec.rb`
|
|
59
59
|
Then the examples should all pass
|
|
60
60
|
|
|
61
61
|
Scenario: overridden in a subsequent RSpec.configure block
|
|
@@ -79,6 +79,6 @@ Feature: custom settings
|
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
"""
|
|
82
|
-
When I run
|
|
82
|
+
When I run `rspec ./additional_setting_spec.rb`
|
|
83
83
|
Then the examples should all pass
|
|
84
84
|
|
|
@@ -21,7 +21,7 @@ Feature: fail fast
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
"""
|
|
24
|
-
When I run
|
|
24
|
+
When I run `rspec spec/example_spec.rb`
|
|
25
25
|
Then the examples should all pass
|
|
26
26
|
|
|
27
27
|
Scenario: fail_fast with first example failing (only runs the one example)
|
|
@@ -37,7 +37,7 @@ Feature: fail fast
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
"""
|
|
40
|
-
When I run
|
|
40
|
+
When I run `rspec spec/example_spec.rb -fd`
|
|
41
41
|
Then the output should contain "1 example, 1 failure"
|
|
42
42
|
|
|
43
43
|
Scenario: fail_fast with multiple files, second example failing (only runs the first two examples)
|
|
@@ -73,5 +73,5 @@ Feature: fail fast
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
"""
|
|
76
|
-
When I run
|
|
76
|
+
When I run `rspec spec`
|
|
77
77
|
Then the output should contain "2 examples, 1 failure"
|
|
@@ -30,7 +30,7 @@ Feature: read command line configuration options from files
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
"""
|
|
33
|
-
When I run
|
|
33
|
+
When I run `rspec ./spec/example_spec.rb`
|
|
34
34
|
Then the examples should all pass
|
|
35
35
|
|
|
36
36
|
Scenario: custom options file
|
|
@@ -47,7 +47,7 @@ Feature: read command line configuration options from files
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
"""
|
|
50
|
-
When I run
|
|
50
|
+
When I run `rspec spec/example_spec.rb --options my.options`
|
|
51
51
|
Then the examples should all pass
|
|
52
52
|
|
|
53
53
|
Scenario: RSpec ignores ./.rspec when custom options file is used
|
|
@@ -67,7 +67,7 @@ Feature: read command line configuration options from files
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
"""
|
|
70
|
-
When I run
|
|
70
|
+
When I run `rspec spec/example_spec.rb --options my.options`
|
|
71
71
|
Then the examples should all pass
|
|
72
72
|
|
|
73
73
|
Scenario: using ERB in .rspec
|
|
@@ -83,5 +83,5 @@ Feature: read command line configuration options from files
|
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
"""
|
|
86
|
-
When I run
|
|
86
|
+
When I run `rspec ./spec/example_spec.rb`
|
|
87
87
|
Then the examples should all pass
|
|
@@ -4,21 +4,17 @@ Feature: basic structure (describe/it)
|
|
|
4
4
|
behave, organized in groups. It uses the words "describe" and "it" so we can
|
|
5
5
|
express concepts like a conversation:
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
"Describe an account when it is first opened."
|
|
8
|
+
"It has a balance of zero."
|
|
9
9
|
|
|
10
|
-
The describe
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Within a group, you can declare nested groups using the describe() or
|
|
15
|
-
context() methods. A nested group is actually a subclass of the outer group,
|
|
16
|
-
so it has access to same methods as the outer group, as well as any class
|
|
17
|
-
methods defined in the outer group.
|
|
18
|
-
|
|
19
|
-
The it() method accepts a block, which is later executed in the context of
|
|
20
|
-
an instance of the group in which it is declared.
|
|
10
|
+
The `describe` method creates an example group. Within the block passed to
|
|
11
|
+
`describe` you can declare nested groups using the `describe` or `context`
|
|
12
|
+
methods, or you can declare examples using the `it` or `specify` methods.
|
|
21
13
|
|
|
14
|
+
Under the hood, an example group is a class in which the block passed to
|
|
15
|
+
`describe` or `context` is evaluated. The blocks passed to `it` are evaluated
|
|
16
|
+
in the context of an _instance_ of that class.
|
|
17
|
+
|
|
22
18
|
Scenario: one group, one example
|
|
23
19
|
Given a file named "sample_spec.rb" with:
|
|
24
20
|
"""
|
|
@@ -27,7 +23,7 @@ Feature: basic structure (describe/it)
|
|
|
27
23
|
end
|
|
28
24
|
end
|
|
29
25
|
"""
|
|
30
|
-
When I run
|
|
26
|
+
When I run `rspec sample_spec.rb -fn`
|
|
31
27
|
Then the output should contain:
|
|
32
28
|
"""
|
|
33
29
|
something
|
|
@@ -48,7 +44,7 @@ Feature: basic structure (describe/it)
|
|
|
48
44
|
end
|
|
49
45
|
end
|
|
50
46
|
"""
|
|
51
|
-
When I run
|
|
47
|
+
When I run `rspec nested_example_groups_spec.rb -fdoc`
|
|
52
48
|
Then the output should contain:
|
|
53
49
|
"""
|
|
54
50
|
something
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Feature: shared context
|
|
2
|
+
|
|
3
|
+
Use `shared_context` to define a block that will be evaluated in the context
|
|
4
|
+
of example groups either explicitly, using `include_context`, or implicitly by
|
|
5
|
+
matching metdata.
|
|
6
|
+
|
|
7
|
+
Background:
|
|
8
|
+
Given a file named "shared_stuff.rb" with:
|
|
9
|
+
"""
|
|
10
|
+
shared_context "shared stuff", :a => :b do
|
|
11
|
+
before { @some_var = :some_value }
|
|
12
|
+
def shared_method
|
|
13
|
+
"it works"
|
|
14
|
+
end
|
|
15
|
+
let(:shared_let) { {'arbitrary' => 'object'} }
|
|
16
|
+
subject do
|
|
17
|
+
'this is the subject'
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
Scenario: declare shared context and include it with include_context
|
|
23
|
+
Given a file named "shared_context_example.rb" with:
|
|
24
|
+
"""
|
|
25
|
+
require "./shared_stuff.rb"
|
|
26
|
+
|
|
27
|
+
describe "group that includes a shared context using 'include_context'" do
|
|
28
|
+
include_context "shared stuff"
|
|
29
|
+
|
|
30
|
+
it "has access to methods defined in shared context" do
|
|
31
|
+
shared_method.should eq("it works")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "has access to methods defined with let in shared context" do
|
|
35
|
+
shared_let['arbitrary'].should eq('object')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "runs the before hooks defined in the shared context" do
|
|
39
|
+
@some_var.should be(:some_value)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "accesses the subject defined in the shared context" do
|
|
43
|
+
subject.should eq('this is the subject')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
"""
|
|
47
|
+
When I run `rspec shared_context_example.rb`
|
|
48
|
+
Then the examples should all pass
|
|
49
|
+
|
|
50
|
+
Scenario: declare shared context and include it with metadata
|
|
51
|
+
Given a file named "shared_context_example.rb" with:
|
|
52
|
+
"""
|
|
53
|
+
require "./shared_stuff.rb"
|
|
54
|
+
|
|
55
|
+
describe "group that includes a shared context using metadata", :a => :b do
|
|
56
|
+
it "has access to methods defined in shared context" do
|
|
57
|
+
shared_method.should eq("it works")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "has access to methods defined with let in shared context" do
|
|
61
|
+
shared_let['arbitrary'].should eq('object')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "runs the before hooks defined in the shared context" do
|
|
65
|
+
@some_var.should be(:some_value)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "accesses the subject defined in the shared context" do
|
|
69
|
+
subject.should eq('this is the subject')
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
"""
|
|
73
|
+
When I run `rspec shared_context_example.rb`
|
|
74
|
+
Then the examples should all pass
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
Feature: shared
|
|
1
|
+
Feature: shared examples
|
|
2
2
|
|
|
3
|
-
Shared
|
|
3
|
+
Shared examples let you describe behaviour of types or modules. When
|
|
4
4
|
declared, a shared group's content is stored. It is only realized in the
|
|
5
5
|
context of another example group, which provides any context the shared group
|
|
6
6
|
needs to run.
|
|
7
7
|
|
|
8
|
-
A shared group is included in another group using
|
|
9
|
-
|
|
8
|
+
A shared group is included in another group using any of:
|
|
9
|
+
|
|
10
|
+
include_examples "name" # include the examples in the current context
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
it_behaves_like "name" # include the examples in a nested context
|
|
13
|
+
it_should_behave_like "name" # include the examples in a nested context
|
|
14
|
+
|
|
15
|
+
Scenario: shared examples group included in two groups
|
|
12
16
|
Given a file named "collection_spec.rb" with:
|
|
13
17
|
"""
|
|
14
18
|
require "set"
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
shared_examples "a collection" do
|
|
17
21
|
let(:collection) { described_class.new([7, 2, 4]) }
|
|
18
22
|
|
|
19
23
|
context "initialized with 3 items" do
|
|
@@ -45,7 +49,7 @@ Feature: shared example group
|
|
|
45
49
|
it_behaves_like "a collection"
|
|
46
50
|
end
|
|
47
51
|
"""
|
|
48
|
-
When I run
|
|
52
|
+
When I run `rspec collection_spec.rb --format documentation`
|
|
49
53
|
Then the examples should all pass
|
|
50
54
|
And the output should contain:
|
|
51
55
|
"""
|
|
@@ -75,7 +79,7 @@ Feature: shared example group
|
|
|
75
79
|
"""
|
|
76
80
|
require "set"
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
shared_examples "a collection object" do
|
|
79
83
|
describe "<<" do
|
|
80
84
|
it "adds objects to the end of the collection" do
|
|
81
85
|
collection << 1
|
|
@@ -86,28 +90,28 @@ Feature: shared example group
|
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
describe Array do
|
|
89
|
-
|
|
93
|
+
it_behaves_like "a collection object" do
|
|
90
94
|
let(:collection) { Array.new }
|
|
91
95
|
end
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
describe Set do
|
|
95
|
-
|
|
99
|
+
it_behaves_like "a collection object" do
|
|
96
100
|
let(:collection) { Set.new }
|
|
97
101
|
end
|
|
98
102
|
end
|
|
99
103
|
"""
|
|
100
|
-
When I run
|
|
104
|
+
When I run `rspec shared_example_group_spec.rb --format documentation`
|
|
101
105
|
Then the examples should all pass
|
|
102
106
|
And the output should contain:
|
|
103
107
|
"""
|
|
104
108
|
Array
|
|
105
|
-
|
|
109
|
+
behaves like a collection object
|
|
106
110
|
<<
|
|
107
111
|
adds objects to the end of the collection
|
|
108
112
|
|
|
109
113
|
Set
|
|
110
|
-
|
|
114
|
+
behaves like a collection object
|
|
111
115
|
<<
|
|
112
116
|
adds objects to the end of the collection
|
|
113
117
|
"""
|
|
@@ -115,7 +119,7 @@ Feature: shared example group
|
|
|
115
119
|
Scenario: Passing parameters to a shared example group
|
|
116
120
|
Given a file named "shared_example_group_params_spec.rb" with:
|
|
117
121
|
"""
|
|
118
|
-
|
|
122
|
+
shared_examples "a measurable object" do |measurement, measurement_methods|
|
|
119
123
|
measurement_methods.each do |measurement_method|
|
|
120
124
|
it "should return #{measurement} from ##{measurement_method}" do
|
|
121
125
|
subject.send(measurement_method).should == measurement
|
|
@@ -133,7 +137,7 @@ Feature: shared example group
|
|
|
133
137
|
it_should_behave_like "a measurable object", 6, [:size, :length]
|
|
134
138
|
end
|
|
135
139
|
"""
|
|
136
|
-
When I run
|
|
140
|
+
When I run `rspec shared_example_group_params_spec.rb --format documentation`
|
|
137
141
|
Then the examples should all pass
|
|
138
142
|
And the output should contain:
|
|
139
143
|
"""
|
|
@@ -155,7 +159,7 @@ Feature: shared example group
|
|
|
155
159
|
c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
|
|
156
160
|
end
|
|
157
161
|
|
|
158
|
-
|
|
162
|
+
shared_examples 'sortability' do
|
|
159
163
|
it 'responds to <=>' do
|
|
160
164
|
sortable.should respond_to(:<=>)
|
|
161
165
|
end
|
|
@@ -167,7 +171,7 @@ Feature: shared example group
|
|
|
167
171
|
end
|
|
168
172
|
end
|
|
169
173
|
"""
|
|
170
|
-
When I run
|
|
174
|
+
When I run `rspec shared_example_group_spec.rb --format documentation`
|
|
171
175
|
Then the examples should all pass
|
|
172
176
|
And the output should contain:
|
|
173
177
|
"""
|
|
@@ -9,6 +9,10 @@ Feature: configure expectation framework
|
|
|
9
9
|
* minitest assertions in ruby 1.9
|
|
10
10
|
* rspec/expecations _and_ stlib assertions
|
|
11
11
|
|
|
12
|
+
Note that when you do not use rspec-expectations, you must explicitly
|
|
13
|
+
provide a description to every example. You cannot rely on the generated
|
|
14
|
+
descriptions provided by rspec-expectations.
|
|
15
|
+
|
|
12
16
|
Scenario: configure rspec-expectations (explicitly)
|
|
13
17
|
Given a file named "example_spec.rb" with:
|
|
14
18
|
"""
|
|
@@ -22,7 +26,7 @@ Feature: configure expectation framework
|
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
"""
|
|
25
|
-
When I run
|
|
29
|
+
When I run `rspec example_spec.rb`
|
|
26
30
|
Then the examples should all pass
|
|
27
31
|
|
|
28
32
|
Scenario: configure test/unit assertions
|
|
@@ -36,10 +40,17 @@ Feature: configure expectation framework
|
|
|
36
40
|
it "is greater than 4" do
|
|
37
41
|
assert 5 > 4, "expected 5 to be greater than 4"
|
|
38
42
|
end
|
|
43
|
+
|
|
44
|
+
specify { assert 5 < 6 }
|
|
39
45
|
end
|
|
40
46
|
"""
|
|
41
|
-
When I run
|
|
42
|
-
Then the
|
|
47
|
+
When I run `rspec example_spec.rb`
|
|
48
|
+
Then the output should contain "2 examples, 1 failure"
|
|
49
|
+
And the output should contain:
|
|
50
|
+
"""
|
|
51
|
+
NotImplementedError:
|
|
52
|
+
Generated descriptions are only supported when you use rspec-expectations.
|
|
53
|
+
"""
|
|
43
54
|
|
|
44
55
|
Scenario: configure rspec/expecations AND test/unit assertions
|
|
45
56
|
Given a file named "example_spec.rb" with:
|
|
@@ -58,5 +69,5 @@ Feature: configure expectation framework
|
|
|
58
69
|
end
|
|
59
70
|
end
|
|
60
71
|
"""
|
|
61
|
-
When I run
|
|
72
|
+
When I run `rspec example_spec.rb`
|
|
62
73
|
Then the examples should all pass
|
|
@@ -2,6 +2,9 @@ Feature: exclusion filters
|
|
|
2
2
|
|
|
3
3
|
You can exclude examples from a run by declaring an exclusion filter and
|
|
4
4
|
then tagging examples, or entire groups, with that filter.
|
|
5
|
+
|
|
6
|
+
If you set the `treat_symbols_as_metadata_keys_with_true_values` config option
|
|
7
|
+
to `true`, you can specify metadata using only symbols.
|
|
5
8
|
|
|
6
9
|
Scenario: exclude an example
|
|
7
10
|
Given a file named "spec/sample_spec.rb" with:
|
|
@@ -20,7 +23,7 @@ Feature: exclusion filters
|
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
"""
|
|
23
|
-
When I run
|
|
26
|
+
When I run `rspec ./spec/sample_spec.rb --format doc`
|
|
24
27
|
Then the output should contain "does one thing"
|
|
25
28
|
And the output should not contain "does another thing"
|
|
26
29
|
|
|
@@ -44,7 +47,7 @@ Feature: exclusion filters
|
|
|
44
47
|
end
|
|
45
48
|
end
|
|
46
49
|
"""
|
|
47
|
-
When I run
|
|
50
|
+
When I run `rspec ./spec/sample_spec.rb --format doc`
|
|
48
51
|
Then the output should contain "group 2 example 1"
|
|
49
52
|
And the output should not contain "group 1 example 1"
|
|
50
53
|
And the output should not contain "group 1 example 2"
|
|
@@ -77,7 +80,7 @@ Feature: exclusion filters
|
|
|
77
80
|
end
|
|
78
81
|
end
|
|
79
82
|
"""
|
|
80
|
-
When I run
|
|
83
|
+
When I run `rspec ./spec/sample_spec.rb --format doc`
|
|
81
84
|
Then the output should match /No examples were matched. Perhaps \{.*:broken=>true.*\} is excluding everything?/
|
|
82
85
|
And the examples should all pass
|
|
83
86
|
And the output should not contain "group 1"
|
|
@@ -108,8 +111,29 @@ Feature: exclusion filters
|
|
|
108
111
|
end
|
|
109
112
|
end
|
|
110
113
|
"""
|
|
111
|
-
When I run
|
|
114
|
+
When I run `rspec ./spec/before_after_all_exclusion_filter_spec.rb`
|
|
112
115
|
Then the output should contain "before all in included group"
|
|
113
116
|
And the output should contain "after all in included group"
|
|
114
117
|
And the output should not contain "before all in excluded group"
|
|
115
118
|
And the output should not contain "after all in excluded group"
|
|
119
|
+
|
|
120
|
+
Scenario: Use symbols as metadata
|
|
121
|
+
Given a file named "symbols_as_metadata_spec.rb" with:
|
|
122
|
+
"""
|
|
123
|
+
RSpec.configure do |c|
|
|
124
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
|
125
|
+
c.filter_run_excluding :broken
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
describe "something" do
|
|
129
|
+
it "does one thing" do
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# tag example for exclusion by adding metadata
|
|
133
|
+
it "does another thing", :broken do
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
"""
|
|
137
|
+
When I run `rspec symbols_as_metadata_spec.rb --format doc`
|
|
138
|
+
Then the output should contain "does one thing"
|
|
139
|
+
And the output should not contain "does another thing"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Feature:
|
|
1
|
+
Feature: :if and :unless
|
|
2
2
|
|
|
3
3
|
The `:if` and `:unless` metadata keys can be used to filter examples without
|
|
4
4
|
needing to configure an exclusion filter.
|
|
@@ -24,7 +24,7 @@ Feature: implicit filters
|
|
|
24
24
|
it("no :if group no :if example") { }
|
|
25
25
|
end
|
|
26
26
|
"""
|
|
27
|
-
When I run
|
|
27
|
+
When I run `rspec implicit_if_filter_spec.rb --format doc`
|
|
28
28
|
Then the output should contain all of these:
|
|
29
29
|
| :if => true group :if => true example |
|
|
30
30
|
| :if => true group no :if example |
|
|
@@ -58,7 +58,7 @@ Feature: implicit filters
|
|
|
58
58
|
it("no :unless group no :unless example") { }
|
|
59
59
|
end
|
|
60
60
|
"""
|
|
61
|
-
When I run
|
|
61
|
+
When I run `rspec implicit_unless_filter_spec.rb --format doc`
|
|
62
62
|
Then the output should contain all of these:
|
|
63
63
|
| :unless => true group :unless => false example |
|
|
64
64
|
| :unless => false group :unless => false example |
|
|
@@ -94,7 +94,7 @@ Feature: implicit filters
|
|
|
94
94
|
it("unfocused :unless => false example", :unless => false) { }
|
|
95
95
|
end
|
|
96
96
|
"""
|
|
97
|
-
When I run
|
|
97
|
+
When I run `rspec explicit_inclusion_filter_spec.rb --format doc`
|
|
98
98
|
Then the output should contain all of these:
|
|
99
99
|
| focused example |
|
|
100
100
|
| focused :if => true example |
|
|
@@ -127,7 +127,7 @@ Feature: implicit filters
|
|
|
127
127
|
it("excluded :unless => false example", :unless => false) { }
|
|
128
128
|
end
|
|
129
129
|
"""
|
|
130
|
-
When I run
|
|
130
|
+
When I run `rspec explicit_exclusion_filter_spec.rb --format doc`
|
|
131
131
|
Then the output should contain all of these:
|
|
132
132
|
| included example |
|
|
133
133
|
| included :if => true example |
|
|
@@ -156,11 +156,13 @@ Feature: implicit filters
|
|
|
156
156
|
it(":unless => :exclude_me_for_unless example", :unless => :exclude_me_for_unless) { }
|
|
157
157
|
end
|
|
158
158
|
"""
|
|
159
|
-
When I run
|
|
159
|
+
When I run `rspec override_implicit_filters_spec.rb --format doc`
|
|
160
160
|
Then the output should contain all of these:
|
|
161
161
|
| :if => true example |
|
|
162
162
|
| :if => false example |
|
|
163
163
|
| :unless => true example |
|
|
164
164
|
| :unless => false example |
|
|
165
|
-
And the output should not contain
|
|
165
|
+
And the output should not contain any of these:
|
|
166
|
+
| :if => :exclude_me example |
|
|
167
|
+
| :unless => :exclude_me_for_unless example |
|
|
166
168
|
|