|
5 | 5 | require "socket" |
6 | 6 | require "open3" |
7 | 7 | require "json" |
| 8 | +require "stringio" |
| 9 | +require "ruby_lsp/ruby_lsp_rspec/rspec_formatter" |
8 | 10 |
|
9 | 11 | RSpec.describe "RubyLsp::RSpec::RSpecFormatter" do |
10 | 12 | it "sends correct LSP events during test execution" do |
|
135 | 137 |
|
136 | 138 | expect(events).to eq(expected) |
137 | 139 | end |
| 140 | + |
| 141 | + describe "RubyLsp::RSpec::RSpecFormatter notifications" do |
| 142 | + let(:output) { StringIO.new } |
| 143 | + let(:formatter) { RubyLsp::RSpec::RSpecFormatter.new(output) } |
| 144 | + let(:notification) { double("Notification") } |
| 145 | + let(:example) { double("Example") } |
| 146 | + |
| 147 | + before do |
| 148 | + allow(notification).to receive(:example).and_return(example) |
| 149 | + allow(example).to receive(:file_path).and_return("spec/fixtures/rspec_example_spec.rb") |
| 150 | + allow(example).to receive(:location).and_return("./spec/fixtures/rspec_example_spec.rb:13") |
| 151 | + allow(example).to receive(:example_group).and_return(double("ExampleGroup", parent_groups: [])) |
| 152 | + end |
| 153 | + |
| 154 | + it "is a subclass of ProgressFormatter" do |
| 155 | + expect(RubyLsp::RSpec::RSpecFormatter.superclass).to eq(RSpec::Core::Formatters::ProgressFormatter) |
| 156 | + end |
| 157 | + |
| 158 | + it "registers necessary notifications with RSpec" do |
| 159 | + registered_notifications = RSpec::Core::Formatters::Loader.formatters[RubyLsp::RSpec::RSpecFormatter] |
| 160 | + |
| 161 | + expect(registered_notifications).to match_array([ |
| 162 | + :example_passed, |
| 163 | + :example_pending, |
| 164 | + :example_failed, |
| 165 | + :example_started, |
| 166 | + :start_dump, |
| 167 | + :stop, |
| 168 | + ]) |
| 169 | + end |
| 170 | + |
| 171 | + it "invokes ProgressFormatter's example_passed" do |
| 172 | + expect_any_instance_of(RSpec::Core::Formatters::ProgressFormatter).to receive(:example_passed) |
| 173 | + |
| 174 | + formatter.example_passed(notification) |
| 175 | + end |
| 176 | + |
| 177 | + it "invokes ProgressFormatter's example_failed" do |
| 178 | + exception = double("Exception", message: "error message") |
| 179 | + allow(notification).to receive(:exception).and_return(exception) |
| 180 | + |
| 181 | + expect_any_instance_of(RSpec::Core::Formatters::ProgressFormatter).to receive(:example_failed) |
| 182 | + |
| 183 | + formatter.example_failed(notification) |
| 184 | + end |
| 185 | + |
| 186 | + it "invokes ProgressFormatter's example_pending" do |
| 187 | + expect_any_instance_of(RSpec::Core::Formatters::ProgressFormatter).to receive(:example_pending) |
| 188 | + |
| 189 | + formatter.example_pending(notification) |
| 190 | + end |
| 191 | + |
| 192 | + it "invokes ProgressFormatter's start_dump" do |
| 193 | + dump_notification = double("DumpNotification") |
| 194 | + expect_any_instance_of(RSpec::Core::Formatters::ProgressFormatter).to receive(:start_dump) |
| 195 | + |
| 196 | + formatter.start_dump(dump_notification) |
| 197 | + end |
| 198 | + end |
138 | 199 | end |
0 commit comments