|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe RspecApiDocumentation::Views::SlateExample do |
| 4 | + let(:metadata) { { :resource_name => "Orders" } } |
| 5 | + let(:group) { RSpec::Core::ExampleGroup.describe("Orders", metadata) } |
| 6 | + let(:rspec_example) { group.example("Ordering a cup of coffee") {} } |
| 7 | + let(:rad_example) do |
| 8 | + RspecApiDocumentation::Example.new(rspec_example, configuration) |
| 9 | + end |
| 10 | + let(:configuration) { RspecApiDocumentation::Configuration.new } |
| 11 | + let(:slate_example) { described_class.new(rad_example, configuration) } |
| 12 | + |
| 13 | + describe '#curl_with_linebreaks' do |
| 14 | + subject { slate_example.curl_with_linebreaks } |
| 15 | + |
| 16 | + before(:each) { allow(slate_example).to receive(:requests).and_return requests } |
| 17 | + |
| 18 | + context 'marshaling' do |
| 19 | + let(:requests) { [{curl: 'One'}, {curl: "Two \nThree" }, {curl: 'Four '}] } |
| 20 | + |
| 21 | + it 'joins all the Curl requests with linebreaks, stripping trailing whitespace' do |
| 22 | + expect(subject).to be == [ |
| 23 | + 'One', 'Two', 'Three', 'Four' |
| 24 | + ].join('<br>') |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'escaping' do |
| 29 | + let(:requests) { [{curl: string}] } |
| 30 | + |
| 31 | + context 'spaces' do |
| 32 | + let(:string) { 'a b' } |
| 33 | + |
| 34 | + it 'replaces them with nonbreaking spaces' do |
| 35 | + expect(subject).to be == 'a b' |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context 'tabs' do |
| 40 | + let(:string) { "a\tb" } |
| 41 | + |
| 42 | + it 'replaces them with two nonbreaking spaces' do |
| 43 | + expect(subject).to be == 'a b' |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'backslashes' do |
| 48 | + let(:string) { 'a\\b'} |
| 49 | + |
| 50 | + it 'replaces them with an HTML entity' do |
| 51 | + expect(subject).to be == 'a\b' |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | +end |
0 commit comments