Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit d562c27

Browse files
authored
Add formatter spec using real classes
1 parent c9cefaf commit d562c27

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

spec/rspec/core/formatters_spec.rb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,26 @@ module RSpec::Core::Formatters
145145
}.to change { loader.formatters.length }
146146
end
147147

148-
context "formatters do not subclass BaseFormatter" do
149-
before do
150-
stub_const("CustomFormatter", Class.new)
151-
stub_const("OtherCustomFormatter", Class.new)
152-
Loader.formatters[CustomFormatter] = []
153-
Loader.formatters[OtherCustomFormatter] = []
154-
loader.add "CustomFormatter"
155-
end
148+
plain_old_formatter = Class.new do
149+
RSpec::Core::Formatters.register self, :example_started
156150

157-
it "adds different formatters" do
158-
expect {
159-
loader.add "OtherCustomFormatter"
160-
}.to change { loader.formatters.length }
151+
def initialize(output)
161152
end
153+
end
162154

163-
it "doesn't add the same formatter" do
164-
expect {
165-
loader.add "CustomFormatter"
166-
}.not_to change { loader.formatters.length }
167-
end
155+
it "handles formatters which do not subclass our formatters" do
156+
expect {
157+
loader.add plain_old_formatter, output
158+
}.to change { loader.formatters.length }
159+
160+
# deliberate duplicate to ensure we can check for them correctly
161+
expect {
162+
loader.add plain_old_formatter, output
163+
}.to_not change { loader.formatters.length }
168164
end
169165
end
170166

171-
context "When a custom formatter exists" do
167+
context "when a custom formatter exists" do
172168
specific_formatter = RSpec::Core::Formatters::JsonFormatter
173169
generic_formatter = specific_formatter.superclass
174170

0 commit comments

Comments
 (0)