rspec-core 2.5.0 → 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 +26 -32
- data/features/Changelog.md +62 -2
- 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/autotest/rspec2.rb +2 -51
- 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/autotest/rspec_spec.rb +4 -126
- 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 +34 -15
- data/spec/ruby_forker.rb +0 -13
|
@@ -5,31 +5,25 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
|
|
|
5
5
|
let(:out) { StringIO.new }
|
|
6
6
|
let(:err) { StringIO.new }
|
|
7
7
|
|
|
8
|
+
include_context "spec files"
|
|
9
|
+
|
|
10
|
+
def command_line(args)
|
|
11
|
+
RSpec::Core::DRbCommandLine.new(config_options(args))
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
def config_options(argv=[])
|
|
9
15
|
options = RSpec::Core::ConfigurationOptions.new(argv)
|
|
10
16
|
options.parse_options
|
|
11
17
|
options
|
|
12
18
|
end
|
|
13
19
|
|
|
14
|
-
def drb_command_line(args)
|
|
15
|
-
RSpec::Core::DRbCommandLine.new(config_options(args))
|
|
16
|
-
end
|
|
17
|
-
|
|
18
20
|
def run_with(args)
|
|
19
|
-
|
|
21
|
+
command_line(args).run(err, out)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
context "without server running" do
|
|
23
|
-
it "
|
|
24
|
-
run_with []
|
|
25
|
-
|
|
26
|
-
err.rewind
|
|
27
|
-
err.read.should =~ /No DRb server is running/
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "returns false" do
|
|
31
|
-
result = run_with []
|
|
32
|
-
result.should be_false
|
|
25
|
+
it "raises an error" do
|
|
26
|
+
lambda { run_with [] }.should raise_error(DRb::DRbConnError)
|
|
33
27
|
end
|
|
34
28
|
end
|
|
35
29
|
|
|
@@ -47,14 +41,14 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
|
|
|
47
41
|
context "without RSPEC_DRB environment variable set" do
|
|
48
42
|
it "defaults to 8989" do
|
|
49
43
|
with_RSPEC_DRB_set_to(nil) do
|
|
50
|
-
|
|
44
|
+
command_line([]).drb_port.should == 8989
|
|
51
45
|
end
|
|
52
46
|
end
|
|
53
47
|
|
|
54
48
|
it "sets the DRb port" do
|
|
55
49
|
with_RSPEC_DRB_set_to(nil) do
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
command_line(["--drb-port", "1234"]).drb_port.should == 1234
|
|
51
|
+
command_line(["--drb-port", "5678"]).drb_port.should == 5678
|
|
58
52
|
end
|
|
59
53
|
end
|
|
60
54
|
end
|
|
@@ -64,7 +58,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
|
|
|
64
58
|
context "without config variable set" do
|
|
65
59
|
it "uses RSPEC_DRB value" do
|
|
66
60
|
with_RSPEC_DRB_set_to('9000') do
|
|
67
|
-
|
|
61
|
+
command_line([]).drb_port.should == "9000"
|
|
68
62
|
end
|
|
69
63
|
end
|
|
70
64
|
end
|
|
@@ -72,7 +66,7 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
|
|
|
72
66
|
context "and config variable set" do
|
|
73
67
|
it "uses configured value" do
|
|
74
68
|
with_RSPEC_DRB_set_to('9000') do
|
|
75
|
-
|
|
69
|
+
command_line(%w[--drb-port 5678]).drb_port.should == 5678
|
|
76
70
|
end
|
|
77
71
|
end
|
|
78
72
|
end
|
|
@@ -88,59 +82,30 @@ describe "::DRbCommandLine", :ruby => "!jruby" do
|
|
|
88
82
|
end
|
|
89
83
|
end
|
|
90
84
|
|
|
91
|
-
def dummy_spec_filename
|
|
92
|
-
@dummy_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_dummy_spec#{@drb_example_file_counter}.rb"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
85
|
before(:all) do
|
|
96
86
|
@drb_port = 8990
|
|
97
87
|
@drb_example_file_counter = 0
|
|
98
88
|
DRb::start_service("druby://127.0.0.1:#{@drb_port}", ::FakeDrbSpecServer)
|
|
99
89
|
end
|
|
100
90
|
|
|
101
|
-
before(:each) do
|
|
102
|
-
@drb_example_file_counter += 1
|
|
103
|
-
create_dummy_spec_file
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
after(:each) do
|
|
107
|
-
File.delete(dummy_spec_filename)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
91
|
after(:all) do
|
|
111
92
|
DRb::stop_service
|
|
112
93
|
end
|
|
113
94
|
|
|
114
|
-
|
|
115
|
-
File.open(dummy_spec_filename, 'w') do |f|
|
|
116
|
-
f.write %q{
|
|
117
|
-
describe "DUMMY CONTEXT for 'DrbCommandLine with -c option'" do
|
|
118
|
-
it "should be output with green bar" do
|
|
119
|
-
true.should be_true
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "should be output with red bar" do
|
|
123
|
-
raise("I want to see a red bar!")
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
}
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "returns true" do
|
|
95
|
+
it "returns 0 if spec passes" do
|
|
131
96
|
err, out = StringIO.new, StringIO.new
|
|
132
|
-
result =
|
|
133
|
-
result.should
|
|
97
|
+
result = command_line(["--drb-port", @drb_port.to_s, passing_spec_filename]).run(err, out)
|
|
98
|
+
result.should be(0)
|
|
134
99
|
end
|
|
135
100
|
|
|
136
|
-
it "
|
|
101
|
+
it "returns 1 if spec passes" do
|
|
137
102
|
err, out = StringIO.new, StringIO.new
|
|
138
|
-
result =
|
|
139
|
-
result.should
|
|
103
|
+
result = command_line(["--drb-port", @drb_port.to_s, failing_spec_filename]).run(err, out)
|
|
104
|
+
result.should be(1)
|
|
140
105
|
end
|
|
141
106
|
|
|
142
107
|
def run_spec_via_druby
|
|
143
|
-
run_with([
|
|
108
|
+
run_with([failing_spec_filename, "--colour", "--drb-port", @drb_port.to_s])
|
|
144
109
|
out.rewind
|
|
145
110
|
out.read
|
|
146
111
|
end
|
|
@@ -13,6 +13,44 @@ end
|
|
|
13
13
|
module RSpec::Core
|
|
14
14
|
|
|
15
15
|
describe ExampleGroup do
|
|
16
|
+
it_behaves_like "metadata hash builder" do
|
|
17
|
+
def metadata_hash(*args)
|
|
18
|
+
group = ExampleGroup.describe('example description', *args)
|
|
19
|
+
group.metadata
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
|
|
24
|
+
before(:each) do
|
|
25
|
+
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
|
|
26
|
+
Kernel.stub(:warn)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'processes string args as part of the description' do
|
|
30
|
+
group = ExampleGroup.describe("some", "separate", "strings")
|
|
31
|
+
group.description.should == "some separate strings"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'processes symbol args as part of the description' do
|
|
35
|
+
group = ExampleGroup.describe(:some, :separate, :symbols)
|
|
36
|
+
group.description.should == "some separate symbols"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true' do
|
|
41
|
+
let(:group) { ExampleGroup.describe(:symbol) }
|
|
42
|
+
before(:each) do
|
|
43
|
+
RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'does not treat the first argument as a metadata key even if it is a symbol' do
|
|
47
|
+
group.metadata.should_not include(:symbol)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'treats the first argument as part of the description when it is a symbol' do
|
|
51
|
+
group.description.should == "symbol"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
16
54
|
|
|
17
55
|
describe "top level group" do
|
|
18
56
|
it "runs its children" do
|
|
@@ -81,49 +119,119 @@ module RSpec::Core
|
|
|
81
119
|
describe "filtering" do
|
|
82
120
|
let(:world) { World.new }
|
|
83
121
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
group.stub(:world) { world }
|
|
122
|
+
shared_examples "matching filters" do
|
|
123
|
+
context "inclusion" do
|
|
124
|
+
before { world.stub(:inclusion_filter).and_return(filter_metadata) }
|
|
88
125
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
126
|
+
it "includes examples in groups matching filter" do
|
|
127
|
+
group = ExampleGroup.describe("does something", spec_metadata)
|
|
128
|
+
group.stub(:world) { world }
|
|
129
|
+
all_examples = [ group.example("first"), group.example("second") ]
|
|
130
|
+
|
|
131
|
+
group.filtered_examples.should == all_examples
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "includes examples directly matching filter" do
|
|
135
|
+
group = ExampleGroup.describe("does something")
|
|
136
|
+
group.stub(:world) { world }
|
|
137
|
+
filtered_examples = [
|
|
138
|
+
group.example("first", spec_metadata),
|
|
139
|
+
group.example("second", spec_metadata)
|
|
140
|
+
]
|
|
141
|
+
group.example("third (not-filtered)")
|
|
142
|
+
|
|
143
|
+
group.filtered_examples.should == filtered_examples
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context "exclusion" do
|
|
148
|
+
before { world.stub(:exclusion_filter).and_return(filter_metadata) }
|
|
149
|
+
it "excludes examples in groups matching filter" do
|
|
150
|
+
group = ExampleGroup.describe("does something", spec_metadata)
|
|
151
|
+
group.stub(:world) { world }
|
|
152
|
+
all_examples = [ group.example("first"), group.example("second") ]
|
|
153
|
+
|
|
154
|
+
group.filtered_examples.should be_empty
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it "excludes examples directly matching filter" do
|
|
158
|
+
group = ExampleGroup.describe("does something")
|
|
159
|
+
group.stub(:world) { world }
|
|
160
|
+
filtered_examples = [
|
|
161
|
+
group.example("first", spec_metadata),
|
|
162
|
+
group.example("second", spec_metadata)
|
|
163
|
+
]
|
|
164
|
+
unfiltered_example = group.example("third (not-filtered)")
|
|
165
|
+
|
|
166
|
+
group.filtered_examples.should == [unfiltered_example]
|
|
167
|
+
end
|
|
168
|
+
end
|
|
94
169
|
end
|
|
95
170
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
171
|
+
context "matching false" do
|
|
172
|
+
let(:spec_metadata) { { :awesome => false }}
|
|
173
|
+
|
|
174
|
+
context "against false" do
|
|
175
|
+
let(:filter_metadata) { { :awesome => false }}
|
|
176
|
+
include_examples "matching filters"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
context "against 'false'" do
|
|
180
|
+
let(:filter_metadata) { { :awesome => 'false' }}
|
|
181
|
+
include_examples "matching filters"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
context "against :false" do
|
|
185
|
+
let(:filter_metadata) { { :awesome => :false }}
|
|
186
|
+
include_examples "matching filters"
|
|
187
|
+
end
|
|
103
188
|
end
|
|
104
189
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
group = ExampleGroup.describe("does something", :include_me => false)
|
|
108
|
-
group.stub(:world) { world }
|
|
190
|
+
context "matching true" do
|
|
191
|
+
let(:spec_metadata) { { :awesome => true }}
|
|
109
192
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
193
|
+
context "against true" do
|
|
194
|
+
let(:filter_metadata) { { :awesome => true }}
|
|
195
|
+
include_examples "matching filters"
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context "against 'true'" do
|
|
199
|
+
let(:filter_metadata) { { :awesome => 'true' }}
|
|
200
|
+
include_examples "matching filters"
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
context "against :true" do
|
|
204
|
+
let(:filter_metadata) { { :awesome => :true }}
|
|
205
|
+
include_examples "matching filters"
|
|
206
|
+
end
|
|
115
207
|
end
|
|
116
208
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
group = ExampleGroup.describe("does something")
|
|
120
|
-
group.stub(:world) { world }
|
|
209
|
+
context "matching a string" do
|
|
210
|
+
let(:spec_metadata) { { :type => 'special' }}
|
|
121
211
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
212
|
+
context "against a string" do
|
|
213
|
+
let(:filter_metadata) { { :type => 'special' }}
|
|
214
|
+
include_examples "matching filters"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
context "against a symbol" do
|
|
218
|
+
let(:filter_metadata) { { :type => :special }}
|
|
219
|
+
include_examples "matching filters"
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context "matching a symbol" do
|
|
224
|
+
let(:spec_metadata) { { :type => :special }}
|
|
225
|
+
|
|
226
|
+
context "against a string" do
|
|
227
|
+
let(:filter_metadata) { { :type => 'special' }}
|
|
228
|
+
include_examples "matching filters"
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context "against a symbol" do
|
|
232
|
+
let(:filter_metadata) { { :type => :special }}
|
|
233
|
+
include_examples "matching filters"
|
|
234
|
+
end
|
|
127
235
|
end
|
|
128
236
|
|
|
129
237
|
context "with no filters" do
|
|
@@ -189,8 +297,6 @@ module RSpec::Core
|
|
|
189
297
|
group.run.should be_true, "expected examples in group to pass"
|
|
190
298
|
end
|
|
191
299
|
end
|
|
192
|
-
|
|
193
|
-
|
|
194
300
|
end
|
|
195
301
|
|
|
196
302
|
describe '#described_class' do
|
|
@@ -200,16 +306,13 @@ module RSpec::Core
|
|
|
200
306
|
end
|
|
201
307
|
|
|
202
308
|
describe '#description' do
|
|
203
|
-
|
|
204
309
|
it "grabs the description from the metadata" do
|
|
205
310
|
group = ExampleGroup.describe(Object, "my desc") { }
|
|
206
311
|
group.description.should == group.metadata[:example_group][:description]
|
|
207
312
|
end
|
|
208
|
-
|
|
209
313
|
end
|
|
210
314
|
|
|
211
315
|
describe '#metadata' do
|
|
212
|
-
|
|
213
316
|
it "adds the third parameter to the metadata" do
|
|
214
317
|
ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
|
|
215
318
|
end
|
|
@@ -225,7 +328,6 @@ module RSpec::Core
|
|
|
225
328
|
it "adds the line_number to metadata" do
|
|
226
329
|
ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should == __LINE__
|
|
227
330
|
end
|
|
228
|
-
|
|
229
331
|
end
|
|
230
332
|
|
|
231
333
|
[:focus, :focused].each do |example_alias|
|
|
@@ -244,7 +346,6 @@ module RSpec::Core
|
|
|
244
346
|
end
|
|
245
347
|
|
|
246
348
|
describe "#before, after, and around hooks" do
|
|
247
|
-
|
|
248
349
|
it "runs the before alls in order" do
|
|
249
350
|
group = ExampleGroup.describe
|
|
250
351
|
order = []
|
|
@@ -255,7 +356,7 @@ module RSpec::Core
|
|
|
255
356
|
|
|
256
357
|
group.run
|
|
257
358
|
|
|
258
|
-
order.should
|
|
359
|
+
order.should eq([1,2,3])
|
|
259
360
|
end
|
|
260
361
|
|
|
261
362
|
it "runs the before eachs in order" do
|
|
@@ -268,7 +369,7 @@ module RSpec::Core
|
|
|
268
369
|
|
|
269
370
|
group.run
|
|
270
371
|
|
|
271
|
-
order.should
|
|
372
|
+
order.should eq([1,2,3])
|
|
272
373
|
end
|
|
273
374
|
|
|
274
375
|
it "runs the after eachs in reverse order" do
|
|
@@ -281,7 +382,7 @@ module RSpec::Core
|
|
|
281
382
|
|
|
282
383
|
group.run
|
|
283
384
|
|
|
284
|
-
order.should
|
|
385
|
+
order.should eq([3,2,1])
|
|
285
386
|
end
|
|
286
387
|
|
|
287
388
|
it "runs the after alls in reverse order" do
|
|
@@ -294,7 +395,7 @@ module RSpec::Core
|
|
|
294
395
|
|
|
295
396
|
group.run
|
|
296
397
|
|
|
297
|
-
order.should
|
|
398
|
+
order.should eq([3,2,1])
|
|
298
399
|
end
|
|
299
400
|
|
|
300
401
|
it "only runs before/after(:all) hooks from example groups that have specs that run" do
|
|
@@ -325,7 +426,7 @@ module RSpec::Core
|
|
|
325
426
|
unfiltered_group.run
|
|
326
427
|
filtered_group.run
|
|
327
428
|
|
|
328
|
-
hooks_run.should
|
|
429
|
+
hooks_run.should eq([:filtered_before_all, :filtered_after_all])
|
|
329
430
|
end
|
|
330
431
|
|
|
331
432
|
it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
|
|
@@ -372,22 +473,44 @@ module RSpec::Core
|
|
|
372
473
|
]
|
|
373
474
|
end
|
|
374
475
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
group.after(:all) { @ivar.should eq("value") }
|
|
379
|
-
group.example("ignore") { }
|
|
476
|
+
context "after(:all)" do
|
|
477
|
+
let(:outer) { ExampleGroup.describe }
|
|
478
|
+
let(:inner) { outer.describe }
|
|
380
479
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
480
|
+
it "has access to state defined before(:all)" do
|
|
481
|
+
outer.before(:all) { @outer = "outer" }
|
|
482
|
+
inner.before(:all) { @inner = "inner" }
|
|
483
|
+
|
|
484
|
+
outer.after(:all) do
|
|
485
|
+
@outer.should eq("outer")
|
|
486
|
+
@inner.should eq("inner")
|
|
487
|
+
end
|
|
488
|
+
inner.after(:all) do
|
|
489
|
+
@inner.should eq("inner")
|
|
490
|
+
@outer.should eq("outer")
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
outer.run
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
it "cleans up ivars in after(:all)" do
|
|
497
|
+
outer.before(:all) { @outer = "outer" }
|
|
498
|
+
inner.before(:all) { @inner = "inner" }
|
|
499
|
+
|
|
500
|
+
outer.run
|
|
501
|
+
|
|
502
|
+
inner.before_all_ivars[:@inner].should be_nil
|
|
503
|
+
inner.before_all_ivars[:@outer].should be_nil
|
|
504
|
+
outer.before_all_ivars[:@inner].should be_nil
|
|
505
|
+
outer.before_all_ivars[:@outer].should be_nil
|
|
506
|
+
end
|
|
384
507
|
end
|
|
385
508
|
|
|
386
509
|
it "treats an error in before(:each) as a failure" do
|
|
387
510
|
group = ExampleGroup.describe
|
|
388
511
|
group.before(:each) { raise "error in before each" }
|
|
389
512
|
example = group.example("equality") { 1.should == 2}
|
|
390
|
-
group.run
|
|
513
|
+
group.run.should == false
|
|
391
514
|
|
|
392
515
|
example.metadata[:execution_result][:exception].message.should == "error in before each"
|
|
393
516
|
end
|
|
@@ -396,7 +519,7 @@ module RSpec::Core
|
|
|
396
519
|
group = ExampleGroup.describe
|
|
397
520
|
group.before(:all) { raise "error in before all" }
|
|
398
521
|
example = group.example("equality") { 1.should == 2}
|
|
399
|
-
group.run
|
|
522
|
+
group.run.should == false
|
|
400
523
|
|
|
401
524
|
example.metadata.should_not be_nil
|
|
402
525
|
example.metadata[:execution_result].should_not be_nil
|
|
@@ -749,5 +872,39 @@ module RSpec::Core
|
|
|
749
872
|
end
|
|
750
873
|
end
|
|
751
874
|
|
|
875
|
+
describe "#include_context" do
|
|
876
|
+
before do
|
|
877
|
+
shared_context "named this" do
|
|
878
|
+
def foo; 'foo'; end
|
|
879
|
+
end
|
|
880
|
+
end
|
|
881
|
+
|
|
882
|
+
it "includes the named context" do
|
|
883
|
+
group = ExampleGroup.describe do
|
|
884
|
+
include_context "named this"
|
|
885
|
+
it "accesses foo" do
|
|
886
|
+
foo.should eq('foo')
|
|
887
|
+
end
|
|
888
|
+
end
|
|
889
|
+
group.run.should be_true
|
|
890
|
+
end
|
|
891
|
+
end
|
|
892
|
+
|
|
893
|
+
describe "#include_examples" do
|
|
894
|
+
before do
|
|
895
|
+
shared_examples "named this" do
|
|
896
|
+
example("does something") do
|
|
897
|
+
end
|
|
898
|
+
end
|
|
899
|
+
end
|
|
900
|
+
|
|
901
|
+
it "includes the named examples" do
|
|
902
|
+
group = ExampleGroup.describe do
|
|
903
|
+
include_examples "named this"
|
|
904
|
+
end
|
|
905
|
+
group.examples.first.description.should eq("does something")
|
|
906
|
+
end
|
|
907
|
+
end
|
|
908
|
+
|
|
752
909
|
end
|
|
753
910
|
end
|
|
@@ -9,6 +9,66 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
9
9
|
example_group.example('example description')
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
it_behaves_like "metadata hash builder" do
|
|
13
|
+
def metadata_hash(*args)
|
|
14
|
+
example = example_group.example('example description', *args)
|
|
15
|
+
example.metadata
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "auto-generated example descriptions" do
|
|
20
|
+
let(:generated_description) { "the generated description" }
|
|
21
|
+
let(:rspec_example) { example_group.specify { 5.should == 5 } }
|
|
22
|
+
before(:each) { RSpec::Matchers.stub(:generated_description => generated_description) }
|
|
23
|
+
|
|
24
|
+
def expect_with(*frameworks)
|
|
25
|
+
RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
|
|
26
|
+
|
|
27
|
+
if frameworks.include?(:stdlib)
|
|
28
|
+
example_group.class_eval do
|
|
29
|
+
def assert(val)
|
|
30
|
+
raise "Expected #{val} to be true" unless val
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when `expect_with :rspec` is configured" do
|
|
37
|
+
before(:each) { expect_with :rspec }
|
|
38
|
+
|
|
39
|
+
it "generates a description for an example with no description" do
|
|
40
|
+
expect {
|
|
41
|
+
example_group.run
|
|
42
|
+
}.to change { rspec_example.metadata[:description] }.from("").to(generated_description)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when `expect_with :rspec, :stdlib` is configured" do
|
|
47
|
+
before(:each) { expect_with :rspec, :stdlib }
|
|
48
|
+
|
|
49
|
+
it "generates a description for an example with no description" do
|
|
50
|
+
expect {
|
|
51
|
+
example_group.run
|
|
52
|
+
}.to change { rspec_example.metadata[:description] }.from("").to(generated_description)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "when `expect_with :stdlib` is configured" do
|
|
57
|
+
let!(:stdlib_example) { example_group.specify { assert 5 == 5 } }
|
|
58
|
+
before(:each) { expect_with :stdlib }
|
|
59
|
+
|
|
60
|
+
it "does not attempt to get the generated description from RSpec::Matchers" do
|
|
61
|
+
RSpec::Matchers.should_not_receive(:generated_description)
|
|
62
|
+
example_group.run
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "fails an example with no description" do
|
|
66
|
+
example_group.run
|
|
67
|
+
stdlib_example.should have_failed_with(NotImplementedError)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
12
72
|
describe '#described_class' do
|
|
13
73
|
it "returns the class (if any) of the outermost example group" do
|
|
14
74
|
described_class.should == RSpec::Core::Example
|
|
@@ -33,6 +93,14 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
33
93
|
end
|
|
34
94
|
|
|
35
95
|
describe "#run" do
|
|
96
|
+
it "sets its reference to the example group instance to nil" do
|
|
97
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
98
|
+
example('example') { 1.should eq(1) }
|
|
99
|
+
end
|
|
100
|
+
group.run
|
|
101
|
+
group.examples.first.instance_variable_get("@example_group_instance").should be_nil
|
|
102
|
+
end
|
|
103
|
+
|
|
36
104
|
it "runs after(:each) when the example passes" do
|
|
37
105
|
after_run = false
|
|
38
106
|
group = RSpec::Core::ExampleGroup.describe do
|
|
@@ -108,6 +176,35 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
108
176
|
"around (after)"
|
|
109
177
|
])
|
|
110
178
|
end
|
|
179
|
+
|
|
180
|
+
context "clearing ivars" do
|
|
181
|
+
it "sets ivars to nil to prep them for GC" do
|
|
182
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
183
|
+
before(:all) { @before_all = :before_all }
|
|
184
|
+
before(:each) { @before_each = :before_each }
|
|
185
|
+
after(:each) { @after_each = :after_each }
|
|
186
|
+
after(:all) { @after_all = :after_all }
|
|
187
|
+
end
|
|
188
|
+
example = group.example("does something") do
|
|
189
|
+
@in_example = :in_example
|
|
190
|
+
end
|
|
191
|
+
example_group_instance = group.new
|
|
192
|
+
example.run(example_group_instance, double('reporter').as_null_object)
|
|
193
|
+
|
|
194
|
+
%w[@before_all @before_each @after_each @after_all].each do |ivar|
|
|
195
|
+
example_group_instance.instance_variable_get(ivar).should be_nil
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it "does not impact the before_all_ivars which are copied to each example" do
|
|
200
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
201
|
+
before(:all) { @before_all = "abc" }
|
|
202
|
+
example("first") { @before_all.should_not be_nil }
|
|
203
|
+
example("second") { @before_all.should_not be_nil }
|
|
204
|
+
end
|
|
205
|
+
group.run.should be_true
|
|
206
|
+
end
|
|
207
|
+
end
|
|
111
208
|
end
|
|
112
209
|
|
|
113
210
|
describe "#pending" do
|
|
@@ -119,6 +216,19 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
|
|
|
119
216
|
group.run
|
|
120
217
|
group.examples.first.should be_pending
|
|
121
218
|
end
|
|
219
|
+
|
|
220
|
+
it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
|
|
221
|
+
blah = nil
|
|
222
|
+
group = RSpec::Core::ExampleGroup.describe do
|
|
223
|
+
around do |example|
|
|
224
|
+
example.run
|
|
225
|
+
blah = :success
|
|
226
|
+
end
|
|
227
|
+
example { pending }
|
|
228
|
+
end
|
|
229
|
+
group.run
|
|
230
|
+
blah.should be(:success)
|
|
231
|
+
end
|
|
122
232
|
end
|
|
123
233
|
|
|
124
234
|
context "in before(:each)" do
|