rspec-core 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Changelog.md +137 -0
  3. data/README.md +2 -2
  4. data/exe/rspec +2 -23
  5. data/features/README.md +1 -5
  6. data/features/command_line/README.md +7 -10
  7. data/features/command_line/exit_status.feature +1 -1
  8. data/features/command_line/format_option.feature +1 -1
  9. data/features/command_line/init.feature +40 -1
  10. data/features/command_line/line_number_option.feature +2 -2
  11. data/features/command_line/ruby.feature +5 -4
  12. data/features/configuration/enable_global_dsl.feature +54 -0
  13. data/features/example_groups/aliasing.feature +48 -0
  14. data/features/example_groups/basic_structure.feature +1 -1
  15. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  16. data/features/filtering/if_and_unless.feature +0 -30
  17. data/features/formatters/custom_formatter.feature +32 -0
  18. data/features/formatters/regression_tests.feature +95 -0
  19. data/features/hooks/around_hooks.feature +1 -0
  20. data/features/hooks/before_and_after_hooks.feature +2 -2
  21. data/features/mock_framework_integration/use_flexmock.feature +11 -13
  22. data/features/mock_framework_integration/use_mocha.feature +11 -13
  23. data/features/mock_framework_integration/use_rr.feature +11 -13
  24. data/features/mock_framework_integration/use_rspec.feature +11 -13
  25. data/features/pending_and_skipped_examples/README.md +3 -0
  26. data/features/pending_and_skipped_examples/pending_examples.feature +118 -0
  27. data/features/pending_and_skipped_examples/skipped_examples.feature +106 -0
  28. data/features/step_definitions/additional_cli_steps.rb +34 -0
  29. data/features/subject/explicit_subject.feature +1 -1
  30. data/features/subject/one_liner_syntax.feature +71 -0
  31. data/lib/rspec/core.rb +6 -14
  32. data/lib/rspec/core/backtrace_formatter.rb +16 -4
  33. data/lib/rspec/core/command_line.rb +2 -3
  34. data/lib/rspec/core/configuration.rb +114 -125
  35. data/lib/rspec/core/configuration_options.rb +32 -18
  36. data/lib/rspec/core/dsl.rb +80 -18
  37. data/lib/rspec/core/example.rb +84 -33
  38. data/lib/rspec/core/example_group.rb +95 -43
  39. data/lib/rspec/core/filter_manager.rb +31 -40
  40. data/lib/rspec/core/formatters.rb +137 -0
  41. data/lib/rspec/core/formatters/base_formatter.rb +28 -41
  42. data/lib/rspec/core/formatters/base_text_formatter.rb +26 -37
  43. data/lib/rspec/core/formatters/deprecation_formatter.rb +48 -27
  44. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -22
  45. data/lib/rspec/core/formatters/html_formatter.rb +48 -56
  46. data/lib/rspec/core/formatters/html_printer.rb +11 -18
  47. data/lib/rspec/core/formatters/json_formatter.rb +18 -22
  48. data/lib/rspec/core/formatters/legacy_formatter.rb +227 -0
  49. data/lib/rspec/core/formatters/progress_formatter.rb +7 -10
  50. data/lib/rspec/core/hooks.rb +250 -217
  51. data/lib/rspec/core/memoized_helpers.rb +43 -9
  52. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  53. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  54. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  55. data/lib/rspec/core/mocking_adapters/rr.rb +28 -0
  56. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  57. data/lib/rspec/core/notifications.rb +100 -0
  58. data/lib/rspec/core/option_parser.rb +11 -18
  59. data/lib/rspec/core/pending.rb +78 -47
  60. data/lib/rspec/core/project_initializer.rb +2 -49
  61. data/lib/rspec/core/project_initializer/dot_rspec +3 -0
  62. data/lib/rspec/core/project_initializer/spec_helper.rb +82 -0
  63. data/lib/rspec/core/rake_task.rb +5 -14
  64. data/lib/rspec/core/reporter.rb +24 -32
  65. data/lib/rspec/core/ruby_project.rb +1 -1
  66. data/lib/rspec/core/runner.rb +14 -4
  67. data/lib/rspec/core/shared_example_group.rb +40 -13
  68. data/lib/rspec/core/version.rb +1 -1
  69. data/spec/command_line/order_spec.rb +15 -15
  70. data/spec/rspec/core/backtrace_formatter_spec.rb +15 -1
  71. data/spec/rspec/core/command_line_spec.rb +18 -17
  72. data/spec/rspec/core/configuration_options_spec.rb +57 -34
  73. data/spec/rspec/core/configuration_spec.rb +162 -184
  74. data/spec/rspec/core/drb_command_line_spec.rb +5 -7
  75. data/spec/rspec/core/drb_options_spec.rb +2 -2
  76. data/spec/rspec/core/dsl_spec.rb +79 -15
  77. data/spec/rspec/core/example_group_spec.rb +253 -39
  78. data/spec/rspec/core/example_spec.rb +149 -33
  79. data/spec/rspec/core/filter_manager_spec.rb +9 -26
  80. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -5
  81. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +42 -145
  82. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +64 -34
  83. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +15 -28
  84. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  85. data/spec/rspec/core/formatters/{html_formatted-1.8.7.html → html_formatted-2.1.0.html} +22 -44
  86. data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +30 -49
  87. data/spec/rspec/core/formatters/html_formatter_spec.rb +35 -19
  88. data/spec/rspec/core/formatters/json_formatter_spec.rb +42 -40
  89. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +137 -0
  90. data/spec/rspec/core/formatters/progress_formatter_spec.rb +38 -25
  91. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +1 -1
  92. data/spec/rspec/core/formatters_spec.rb +120 -0
  93. data/spec/rspec/core/hooks_filtering_spec.rb +1 -1
  94. data/spec/rspec/core/hooks_spec.rb +13 -2
  95. data/spec/rspec/core/memoized_helpers_spec.rb +17 -8
  96. data/spec/rspec/core/metadata_spec.rb +3 -3
  97. data/spec/rspec/core/option_parser_spec.rb +53 -46
  98. data/spec/rspec/core/ordering_spec.rb +4 -4
  99. data/spec/rspec/core/pending_example_spec.rb +23 -126
  100. data/spec/rspec/core/pending_spec.rb +8 -0
  101. data/spec/rspec/core/project_initializer_spec.rb +8 -41
  102. data/spec/rspec/core/rake_task_spec.rb +15 -4
  103. data/spec/rspec/core/random_spec.rb +1 -1
  104. data/spec/rspec/core/reporter_spec.rb +50 -37
  105. data/spec/rspec/core/resources/formatter_specs.rb +9 -11
  106. data/spec/rspec/core/rspec_matchers_spec.rb +1 -1
  107. data/spec/rspec/core/ruby_project_spec.rb +3 -3
  108. data/spec/rspec/core/runner_spec.rb +65 -23
  109. data/spec/rspec/core/shared_context_spec.rb +4 -4
  110. data/spec/rspec/core/shared_example_group/collection_spec.rb +1 -1
  111. data/spec/rspec/core/shared_example_group_spec.rb +20 -11
  112. data/spec/rspec/core/warnings_spec.rb +1 -1
  113. data/spec/rspec/core/world_spec.rb +10 -10
  114. data/spec/rspec/core_spec.rb +2 -2
  115. data/spec/spec_helper.rb +12 -24
  116. data/spec/support/config_options_helper.rb +1 -3
  117. data/spec/support/formatter_support.rb +83 -0
  118. data/spec/support/isolate_load_path_mutation.rb +1 -2
  119. data/spec/support/isolated_directory.rb +1 -1
  120. data/spec/support/isolated_home_directory.rb +1 -1
  121. data/spec/support/legacy_formatter_using_sub_classing_example.rb +87 -0
  122. data/spec/support/matchers.rb +20 -0
  123. data/spec/support/mathn_integration_support.rb +2 -2
  124. data/spec/support/old_style_formatter_example.rb +69 -0
  125. data/spec/support/shared_example_groups.rb +1 -1
  126. data/spec/support/spec_files.rb +3 -3
  127. metadata +192 -69
  128. metadata.gz.sig +3 -1
  129. checksums.yaml +0 -15
  130. checksums.yaml.gz.sig +0 -2
  131. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/subject/implicit_receiver.feature +0 -29
  134. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  135. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  136. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  137. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  138. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
  139. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
  140. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +0 -416
  141. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
  142. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -419
  143. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
  144. data/spec/support/in_sub_process.rb +0 -37
  145. data/spec/support/sandboxed_mock_space.rb +0 -100
@@ -3,13 +3,13 @@ require "spec_helper"
3
3
  module RSpec
4
4
  module Core
5
5
  module Ordering
6
- describe Identity do
6
+ RSpec.describe Identity do
7
7
  it "does not affect the ordering of the items" do
8
8
  expect(Identity.new.order([1, 2, 3])).to eq([1, 2, 3])
9
9
  end
10
10
  end
11
11
 
12
- describe Random do
12
+ RSpec.describe Random do
13
13
  describe '.order' do
14
14
  subject { described_class.new(configuration) }
15
15
 
@@ -48,7 +48,7 @@ module RSpec
48
48
  end
49
49
  end
50
50
 
51
- describe Custom do
51
+ RSpec.describe Custom do
52
52
  it 'uses the block to order the list' do
53
53
  strategy = Custom.new(proc { |list| list.reverse })
54
54
 
@@ -56,7 +56,7 @@ module RSpec
56
56
  end
57
57
  end
58
58
 
59
- describe Registry do
59
+ RSpec.describe Registry do
60
60
  let(:configuration) { Configuration.new }
61
61
  subject(:registry) { Registry.new(configuration) }
62
62
 
@@ -1,20 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "an example" do
4
- matcher :be_pending_with do |message|
5
- match do |example|
6
- example.pending? && example.metadata[:execution_result][:pending_message] == message
7
- end
8
-
9
- failure_message_for_should do |example|
10
- "expected: example pending with #{message.inspect}\n got: #{example.metadata[:execution_result][:pending_message].inspect}"
11
- end
12
- end
13
-
3
+ RSpec.describe "an example" do
14
4
  context "declared pending with metadata" do
15
5
  it "uses the value assigned to :pending as the message" do
16
6
  group = RSpec::Core::ExampleGroup.describe('group') do
17
7
  example "example", :pending => 'just because' do
8
+ fail
18
9
  end
19
10
  end
20
11
  example = group.examples.first
@@ -25,6 +16,7 @@ describe "an example" do
25
16
  it "sets the message to 'No reason given' if :pending => true" do
26
17
  group = RSpec::Core::ExampleGroup.describe('group') do
27
18
  example "example", :pending => true do
19
+ fail
28
20
  end
29
21
  end
30
22
  example = group.examples.first
@@ -40,7 +32,7 @@ describe "an example" do
40
32
  end
41
33
  example = group.examples.first
42
34
  example.run(group.new, double.as_null_object)
43
- expect(example).to be_pending_with('Not yet implemented')
35
+ expect(example).to be_skipped_with('Not yet implemented')
44
36
  end
45
37
  end
46
38
 
@@ -49,12 +41,30 @@ describe "an example" do
49
41
  group = RSpec::Core::ExampleGroup.describe('group') do
50
42
  it "does something" do
51
43
  pending
44
+ fail
52
45
  end
53
46
  end
54
47
  example = group.examples.first
55
48
  example.run(group.new, double.as_null_object)
56
49
  expect(example).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
57
50
  end
51
+
52
+ it "fails when the rest of the example passes" do
53
+ called = false
54
+ group = RSpec::Core::ExampleGroup.describe('group') do
55
+ it "does something" do
56
+ pending
57
+ called = true
58
+ end
59
+ end
60
+
61
+ example = group.examples.first
62
+ example.run(group.new, double.as_null_object)
63
+ expect(called).to eq(true)
64
+ result = example.metadata[:execution_result]
65
+ expect(result[:pending_fixed]).to eq(true)
66
+ expect(result[:status]).to eq("failed")
67
+ end
58
68
  end
59
69
 
60
70
  context "with no docstring" do
@@ -96,6 +106,7 @@ describe "an example" do
96
106
  group = RSpec::Core::ExampleGroup.describe('group') do
97
107
  it "does something" do
98
108
  pending("just because")
109
+ fail
99
110
  end
100
111
  end
101
112
  example = group.examples.first
@@ -103,118 +114,4 @@ describe "an example" do
103
114
  expect(example).to be_pending_with('just because')
104
115
  end
105
116
  end
106
-
107
- context "with a block" do
108
- def run_example(*pending_args, &block)
109
- group = RSpec::Core::ExampleGroup.describe('group') do
110
- it "does something" do
111
- pending(*pending_args) { block.call if block }
112
- end
113
- end
114
- example = group.examples.first
115
- example.run(group.new, double.as_null_object)
116
- example
117
- end
118
-
119
- context "that fails" do
120
- def run_example(*pending_args)
121
- super(*pending_args) { raise ArgumentError.new }
122
- end
123
-
124
- context "when given no options" do
125
- it "is listed as pending with the supplied message" do
126
- expect(run_example("just because")).to be_pending_with("just because")
127
- end
128
-
129
- it "is listed as pending with the default message when no message is given" do
130
- expect(run_example).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
131
- end
132
- end
133
-
134
- context "when given a truthy :if option" do
135
- it "is listed as pending with the supplied message" do
136
- expect(run_example("just because", :if => true)).to be_pending_with("just because")
137
- end
138
-
139
- it "is listed as pending with the default message when no message is given" do
140
- expect(run_example(:if => true)).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
141
- end
142
- end
143
-
144
- context "when given a falsey :if option" do
145
- it "runs the example and fails" do
146
- expect(run_example( :if => false)).to fail_with(ArgumentError)
147
- expect(run_example("just because", :if => false)).to fail_with(ArgumentError)
148
- end
149
- end
150
-
151
- context "when given a truthy :unless option" do
152
- it "runs the example and fails" do
153
- expect(run_example( :unless => true)).to fail_with(ArgumentError)
154
- expect(run_example("just because", :unless => true)).to fail_with(ArgumentError)
155
- end
156
- end
157
-
158
- context "when given a falsey :unless option" do
159
- it "is listed as pending with the supplied message" do
160
- expect(run_example("just because", :unless => false)).to be_pending_with("just because")
161
- end
162
-
163
- it "is listed as pending with the default message when no message is given" do
164
- expect(run_example(:unless => false)).to be_pending_with(RSpec::Core::Pending::NO_REASON_GIVEN)
165
- end
166
- end
167
- end
168
-
169
- context "that fails due to a failed message expectation" do
170
- def run_example(*pending_args)
171
- super(*pending_args) { "foo".should_receive(:bar) }
172
- end
173
-
174
- it "passes" do
175
- expect(run_example("just because")).to be_pending
176
- end
177
- end
178
-
179
- context "that passes" do
180
- def run_example(*pending_args)
181
- super(*pending_args) { expect(3).to eq(3) }
182
- end
183
-
184
- context "when given no options" do
185
- it "fails with a PendingExampleFixedError" do
186
- expect(run_example("just because")).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
187
- expect(run_example).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
188
- end
189
- end
190
-
191
- context "when given a truthy :if option" do
192
- it "fails with a PendingExampleFixedError" do
193
- expect(run_example("just because", :if => true)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
194
- expect(run_example( :if => true)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
195
- end
196
- end
197
-
198
- context "when given a falsey :if option" do
199
- it "runs the example and it passes" do
200
- expect(run_example( :if => false)).to pass
201
- expect(run_example("just because", :if => false)).to pass
202
- end
203
- end
204
-
205
- context "when given a truthy :unless option" do
206
- it "runs the example and it passes" do
207
- expect(run_example( :unless => true)).to pass
208
- expect(run_example("just because", :unless => true)).to pass
209
- end
210
- end
211
-
212
- context "when given a falsey :unless option" do
213
- it "fails with a PendingExampleFixedError" do
214
- expect(run_example("just because", :unless => false)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
215
- expect(run_example( :unless => false)).to fail_with(RSpec::Core::Pending::PendingExampleFixedError)
216
- end
217
- end
218
- end
219
- end
220
117
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RSpec::Core::Pending do
4
+ it 'only defines methods that are part of the DSL' do
5
+ expect(RSpec::Core::Pending.instance_methods(false).map(&:to_sym)).to \
6
+ match_array([:pending, :skip])
7
+ end
8
+ end
@@ -2,33 +2,33 @@ require "spec_helper"
2
2
  require 'rspec/core/project_initializer'
3
3
 
4
4
  module RSpec::Core
5
- describe ProjectInitializer, :isolated_directory => true do
5
+ RSpec.describe ProjectInitializer, :isolated_directory => true do
6
6
 
7
7
  describe "#run" do
8
8
  context "with no args" do
9
9
  let(:command_line_config) { ProjectInitializer.new }
10
10
 
11
11
  before do
12
- command_line_config.stub(:puts)
13
- command_line_config.stub(:gets => 'no')
12
+ allow(command_line_config).to receive(:puts)
13
+ allow(command_line_config).to receive_messages(:gets => 'no')
14
14
  end
15
15
 
16
16
  context "with no .rspec file" do
17
17
  it "says it's creating .rspec " do
18
- command_line_config.should_receive(:puts).with(/create\s+\.rspec/)
18
+ expect(command_line_config).to receive(:puts).with(/create\s+\.rspec/)
19
19
  command_line_config.run
20
20
  end
21
21
 
22
22
  it "generates a .rspec" do
23
23
  command_line_config.run
24
- expect(File.read('.rspec')).to match(/--color\n--format progress/m)
24
+ expect(File.read('.rspec')).to match(/--color/m)
25
25
  end
26
26
  end
27
27
 
28
28
  context "with a .rspec file" do
29
29
  it "says .rspec exists" do
30
30
  FileUtils.touch('.rspec')
31
- command_line_config.should_receive(:puts).with(/exist\s+\.rspec/)
31
+ expect(command_line_config).to receive(:puts).with(/exist\s+\.rspec/)
32
32
  command_line_config.run
33
33
  end
34
34
 
@@ -41,7 +41,7 @@ module RSpec::Core
41
41
 
42
42
  context "with no spec/spec_helper.rb file" do
43
43
  it "says it's creating spec/spec_helper.rb " do
44
- command_line_config.should_receive(:puts).with(/create\s+spec\/spec_helper.rb/)
44
+ expect(command_line_config).to receive(:puts).with(/create\s+spec\/spec_helper.rb/)
45
45
  command_line_config.run
46
46
  end
47
47
 
@@ -56,7 +56,7 @@ module RSpec::Core
56
56
 
57
57
  it "says spec/spec_helper.rb exists" do
58
58
  FileUtils.touch('spec/spec_helper.rb')
59
- command_line_config.should_receive(:puts).with(/exist\s+spec\/spec_helper.rb/)
59
+ expect(command_line_config).to receive(:puts).with(/exist\s+spec\/spec_helper.rb/)
60
60
  command_line_config.run
61
61
  end
62
62
 
@@ -67,39 +67,6 @@ module RSpec::Core
67
67
  expect(File.read('spec/spec_helper.rb')).to eq(random_content)
68
68
  end
69
69
  end
70
-
71
- context "with lib/tasks/rspec.rake" do
72
- before do
73
- FileUtils.mkdir_p('lib/tasks')
74
- FileUtils.touch 'lib/tasks/rspec.rake'
75
- end
76
-
77
- it "asks whether to delete the file" do
78
- command_line_config.should_receive(:puts).with(/delete/)
79
- command_line_config.run
80
- end
81
-
82
- it "removes it if confirmed" do
83
- command_line_config.stub(:gets => 'yes')
84
- command_line_config.run
85
- expect(File.exist?('lib/tasks/rspec.rake')).to be_falsey
86
- end
87
-
88
- it "leaves it if not confirmed" do
89
- command_line_config.stub(:gets => 'no')
90
- command_line_config.run
91
- expect(File.exist?('lib/tasks/rspec.rake')).to be_truthy
92
- end
93
- end
94
- end
95
-
96
- context "given an arg" do
97
- it "warns if arg received (no longer necessary)" do
98
- config = ProjectInitializer.new("another_arg")
99
- config.stub(:puts)
100
- config.stub(:gets => 'no')
101
- config.run
102
- end
103
70
  end
104
71
  end
105
72
  end
@@ -3,7 +3,7 @@ require "rspec/core/rake_task"
3
3
  require 'tempfile'
4
4
 
5
5
  module RSpec::Core
6
- describe RakeTask do
6
+ RSpec.describe RakeTask do
7
7
  let(:task) { RakeTask.new }
8
8
 
9
9
  def ruby
@@ -28,7 +28,7 @@ module RSpec::Core
28
28
  expect(args[:files]).to eq "first_spec.rb"
29
29
  end
30
30
 
31
- task.should_receive(:run_task) { true }
31
+ expect(task).to receive(:run_task) { true }
32
32
  expect(Rake.application.invoke_task("rake_task_args[first_spec.rb]")).to be_truthy
33
33
  end
34
34
  end
@@ -53,13 +53,24 @@ module RSpec::Core
53
53
  end
54
54
  end
55
55
 
56
+ context 'with custom exit status' do
57
+ it 'returns the correct status on exit', :slow do
58
+ with_isolated_stderr do
59
+ expect($stderr).to receive(:puts) { |cmd| expect(cmd).to match(/-e "exit\(2\);".* failed/) }
60
+ expect(task).to receive(:exit).with(2)
61
+ task.ruby_opts = '-e "exit(2);" ;#'
62
+ task.run_task false
63
+ end
64
+ end
65
+ end
66
+
56
67
  def specify_consistent_ordering_of_files_to_run(pattern, task)
57
68
  orderings = [
58
69
  %w[ a/1.rb a/2.rb a/3.rb ],
59
70
  %w[ a/2.rb a/1.rb a/3.rb ],
60
71
  %w[ a/3.rb a/2.rb a/1.rb ]
61
72
  ].map do |files|
62
- FileList.should_receive(:[]).with(pattern) { files }
73
+ expect(FileList).to receive(:[]).with(pattern) { files }
63
74
  task.__send__(:files_to_run)
64
75
  end
65
76
 
@@ -87,7 +98,7 @@ module RSpec::Core
87
98
 
88
99
  # since the config block is deferred til task invocation, must fake
89
100
  # calling the task so the expected pattern is picked up
90
- task.should_receive(:run_task) { true }
101
+ expect(task).to receive(:run_task) { true }
91
102
  expect(Rake.application.invoke_task(task.name)).to be_truthy
92
103
 
93
104
  specify_consistent_ordering_of_files_to_run('a/*.rb', task)
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Core
5
- describe RandomNumberGenerator do
5
+ RSpec.describe RandomNumberGenerator do
6
6
  it 'is a random number generator' do
7
7
  random = described_class.new
8
8
 
@@ -1,26 +1,23 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module RSpec::Core
4
- describe Reporter do
5
- let(:config) { Configuration.new }
4
+ RSpec.describe Reporter do
5
+ let(:config) { Configuration.new }
6
+ let(:reporter) { Reporter.new config }
6
7
 
7
- def reporter_for(*formatters)
8
- Reporter.new(config, *formatters)
9
- end
10
-
11
- describe "abort" do
8
+ describe "finish" do
12
9
  let(:formatter) { double("formatter") }
13
10
  let(:example) { double("example") }
14
- let(:reporter) { reporter_for(formatter) }
15
11
 
16
- %w[start_dump dump_pending dump_failures dump_summary close].each do |message|
12
+ %w[start_dump dump_pending dump_failures dump_summary close].map(&:to_sym).each do |message|
17
13
  it "sends #{message} to the formatter(s) that respond to message" do
18
- formatter.as_null_object.should_receive(message)
19
- reporter.abort
14
+ reporter.register_listener formatter, message
15
+ expect(formatter.as_null_object).to receive(message)
16
+ reporter.finish
20
17
  end
21
18
 
22
19
  it "doesnt notify formatters about messages they dont implement" do
23
- expect { reporter.abort }.to_not raise_error
20
+ expect { reporter.finish }.to_not raise_error
24
21
  end
25
22
  end
26
23
  end
@@ -29,10 +26,11 @@ module RSpec::Core
29
26
  it "passes messages to that formatter" do
30
27
  formatter = double("formatter", :example_started => nil)
31
28
  example = double("example")
32
- reporter = reporter_for(formatter)
29
+ reporter.register_listener formatter, :example_started
33
30
 
34
- formatter.should_receive(:example_started).
35
- with(example)
31
+ expect(formatter).to receive(:example_started) do |notification|
32
+ expect(notification.example).to eq example
33
+ end
36
34
 
37
35
  reporter.example_started(example)
38
36
  end
@@ -40,9 +38,11 @@ module RSpec::Core
40
38
  it "passes example_group_started and example_group_finished messages to that formatter in that order" do
41
39
  order = []
42
40
 
43
- formatter = double("formatter").as_null_object
44
- formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
45
- formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
41
+ formatter = double("formatter")
42
+ allow(formatter).to receive(:example_group_started) { |n| order << "Started: #{n.group.description}" }
43
+ allow(formatter).to receive(:example_group_finished) { |n| order << "Finished: #{n.group.description}" }
44
+
45
+ reporter.register_listener formatter, :example_group_started, :example_group_finished
46
46
 
47
47
  group = ExampleGroup.describe("root")
48
48
  group.describe("context 1") do
@@ -52,7 +52,7 @@ module RSpec::Core
52
52
  example("ignore") {}
53
53
  end
54
54
 
55
- group.run(reporter_for(formatter))
55
+ group.run(reporter)
56
56
 
57
57
  expect(order).to eq([
58
58
  "Started: root",
@@ -67,13 +67,15 @@ module RSpec::Core
67
67
 
68
68
  context "given an example group with no examples" do
69
69
  it "does not pass example_group_started or example_group_finished to formatter" do
70
- formatter = double("formatter").as_null_object
71
- formatter.should_not_receive(:example_group_started)
72
- formatter.should_not_receive(:example_group_finished)
70
+ formatter = double("formatter")
71
+ expect(formatter).not_to receive(:example_group_started)
72
+ expect(formatter).not_to receive(:example_group_finished)
73
+
74
+ reporter.register_listener formatter, :example_group_started, :example_group_finished
73
75
 
74
76
  group = ExampleGroup.describe("root")
75
77
 
76
- group.run(reporter_for(formatter))
78
+ group.run(reporter)
77
79
  end
78
80
  end
79
81
 
@@ -81,12 +83,12 @@ module RSpec::Core
81
83
  it "passes messages to all formatters" do
82
84
  formatters = (1..2).map { double("formatter", :example_started => nil) }
83
85
  example = double("example")
84
- reporter = reporter_for(*formatters)
85
86
 
86
87
  formatters.each do |formatter|
87
- formatter.
88
- should_receive(:example_started).
89
- with(example)
88
+ expect(formatter).to receive(:example_started) do |notification|
89
+ expect(notification.example).to eq example
90
+ end
91
+ reporter.register_listener formatter, :example_started
90
92
  end
91
93
 
92
94
  reporter.example_started(example)
@@ -95,19 +97,17 @@ module RSpec::Core
95
97
 
96
98
  describe "#report" do
97
99
  it "supports one arg (count)" do
98
- reporter_for.report(1) {}
100
+ reporter.report(1) {}
99
101
  end
100
102
 
101
103
  it "yields itself" do
102
- reporter = reporter_for
103
104
  yielded = nil
104
- reporter.report(3) {|r| yielded = r}
105
+ reporter.report(3) { |r| yielded = r }
105
106
  expect(yielded).to eq(reporter)
106
107
  end
107
108
  end
108
109
 
109
110
  describe "#register_listener" do
110
- let(:reporter) { reporter_for }
111
111
  let(:listener) { double("listener", :start => nil) }
112
112
 
113
113
  before { reporter.register_listener listener, :start }
@@ -116,22 +116,35 @@ module RSpec::Core
116
116
  expect(reporter.registered_listeners :start).to eq [listener]
117
117
  end
118
118
 
119
+ it 'will match string notification names' do
120
+ reporter.register_listener listener, "stop"
121
+ expect(reporter.registered_listeners :stop).to eq [listener]
122
+ end
123
+
119
124
  it 'will send notifications when a subscribed event is triggered' do
120
- listener.should_receive(:start).with(42)
125
+ expect(listener).to receive(:start) do |notification|
126
+ expect(notification.count).to eq 42
127
+ end
128
+ reporter.start 42
129
+ end
130
+
131
+ it 'will ignore duplicated listeners' do
132
+ reporter.register_listener listener, :start
133
+ expect(listener).to receive(:start).once
121
134
  reporter.start 42
122
135
  end
123
136
  end
124
137
 
125
138
  describe "timing" do
126
139
  it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
127
- formatter = double(:formatter).as_null_object
128
- reporter = reporter_for formatter
140
+ formatter = double(:formatter)
141
+ reporter.register_listener formatter, :dump_summary
129
142
  reporter.start 1
130
- Time.stub(:now => ::Time.utc(2012, 10, 1))
143
+ allow(Time).to receive_messages(:now => ::Time.utc(2012, 10, 1))
131
144
 
132
145
  duration = nil
133
- formatter.stub(:dump_summary) do |dur, _, _, _|
134
- duration = dur
146
+ allow(formatter).to receive(:dump_summary) do |notification|
147
+ duration = notification.duration
135
148
  end
136
149
 
137
150
  reporter.finish