require 'cucumber/messages' require 'cucumber/html_formatter' class FakeAssets def template "{{css}}
{{messages}}{{script}}" end def css "" end def script "" end end describe Cucumber::HTMLFormatter::Formatter do let(:subject) { formatter = Cucumber::HTMLFormatter::Formatter.new(out) allow(formatter).to receive(:assets_loader).and_return(assets) formatter } let(:out) { StringIO.new } let(:assets) { FakeAssets.new } context '.write_pre_message' do it 'outputs the content of the template up to {{messages}}' do subject.write_pre_message() expect(out.string).to eq("\n\n\n") end it 'does not write the content twice' do subject.write_pre_message() subject.write_pre_message() expect(out.string).to eq("\n\n\n") end end context '.write_message' do let(:message) do ::Cucumber::Messages::Envelope.new( pickle: ::Cucumber::Messages::Pickle.new(id: 'some-random-uid') ) end it 'appends the message to out' do subject.write_message(message) expect(out.string).to eq(message.to_json) end it 'adds commas between the messages' do subject.write_message(message) subject.write_message(message) expect(out.string).to eq("#{message.to_json},\n#{message.to_json}") end end context '.write_post_message' do it 'outputs the template end' do subject.write_post_message() expect(out.string).to eq("\n\n") end end context '.process_messages' do let(:message) do ::Cucumber::Messages::Envelope.new( pickle: ::Cucumber::Messages::Pickle.new(id: 'some-random-uid') ) end it 'produces the full html report' do subject.process_messages([message]) expect(out.string).to eq([ '', '', '', "#{message.to_json}", "", '' ].join("\n")) end end end