Skip to content

Commit 5a71d28

Browse files
committed
Set up cURL output. [zipmark#275]
1 parent b336cf7 commit 5a71d28

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

lib/rspec_api_documentation/views/slate_example.rb

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def initialize(example, configuration)
55
super
66
self.template_name = "rspec_api_documentation/slate_example"
77
end
8+
9+
def curl_with_linebreaks
10+
requests.map {|request| request[:curl].lines }.flatten.map do |line|
11+
line.rstrip.gsub("\t", ' ').gsub(' ', ' ').gsub('\\', '\')
12+
end.join "<br>"
13+
end
814
end
915
end
1016
end

spec/views/slate_example_spec.rb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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&nbsp;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&nbsp;&nbsp;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&#92;b'
52+
end
53+
end
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)