forked from railsbridge/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_spec.rb
190 lines (168 loc) · 4.89 KB
/
step_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
require 'spec_helper'
require "site"
require "step_page"
describe Step do
before do
setup_test_translations
end
def to_html nokogiri_node
nokogiri_node.serialize(:save_with => 0).chomp
end
def html_doc(src = "step 'hello'; step 'goodbye'")
@html_doc ||= begin
step = Step.new(src: src,
doc_path: "/tmp/hello.step"
)
@html = step.to_html
Nokogiri.parse("<html>#{@html}</html>")
end
end
def step_obj_for(path)
Step.new(src: File.read(path), doc_path: path)
end
it "renders a step file" do
BigCheckbox.number = 1
steps = html_doc.css(".step")
html = to_html(steps.first)
checkbox_html = %q{<input class="big_checkbox" id="big_checkbox_1" name="big_checkbox_1" type="checkbox" value="valuable"><label for="big_checkbox_1"></label>}
expected = <<-HTML.strip_heredoc.gsub("\n", '')
<div class="step">
<h1>#{checkbox_html}<span class="prefix">Step 1: </span>hello</h1>
</div>
HTML
expect(html).to eq(expected)
end
it "puts anchors in based on step numbers" do
steps = html_doc.css(".step")
steps.each_with_index do |step, i|
expect(step.previous).to be_truthy
expect(to_html(step.previous)).to eq("<a name=\"step#{i+1}\"></a>")
end
end
it "puts anchors in based on optional step name" do
html_doc(<<-RUBY)
step "Test", {:anchor_name => 'happy_step'}
RUBY
anchors = html_doc.css("a")
names = anchors.map{|a| a["name"]}
expect(names).to eq(%w(step1 happy_step))
end
it "nests anchor numbers" do
html_doc(<<-RUBY)
step "breakfast" do
step "cereal"
step "eggs"
end
step "lunch" do
step "salad"
step "sandwich"
end
RUBY
anchors = html_doc.css("a")
names = anchors.map{|a| a["name"]}
expect(names).to eq(%w(step1 step1-1 step1-2 step2 step2-1 step2-2))
end
describe 'link' do
it "creates a link" do
html_doc(<<-RUBY)
step "breakfast" do
link "choose_breakfast"
end
step "lunch" do
step "salad"
step "sandwich"
end
RUBY
a = html_doc.css(".step a.link").first
expect(a["href"]).to eq("choose_breakfast")
end
it "has an optional parameter for the caption" do
html_doc(<<-RUBY)
step "breakfast" do
link "breakfast", caption: "Eat some"
end
RUBY
expect(html_doc.css("p.link").text).to eq("Eat some Breakfast")
end
end
describe 'source_code' do
it "emits a block of code as a pre with class 'code'" do
html_doc(<<-RUBY)
source_code "x = 2"
RUBY
expect(@html).to eq("<pre class=\"code\">x = 2</pre>")
end
it "emits a block of code with a language directive" do
html_doc(<<-RUBY)
source_code :ruby, "x = 2"
RUBY
expect(@html).to eq("<pre class=\"code\">\n:::ruby\nx = 2</pre>")
end
end
describe 'console' do
it "emits a 'console' div with a 'pre' block" do
html_doc(<<-RUBY)
console "echo hi"
RUBY
expect(@html).to loosely_equal(<<-HTML.strip_heredoc)
<div class="console">
<span>#{I18n.t('captions.terminal')}</span>
<pre>echo hi</pre>
</div>
HTML
end
end
describe 'result' do
it "emits a 'result' div with a 'pre' block" do
html_doc(<<-RUBY)
result "hi"
RUBY
expect(@html).to loosely_equal(<<-HTML.strip_heredoc)
<div class="result">
<span>#{I18n.t("captions.result")}</span>
<pre>hi</pre>
</div>
HTML
end
end
describe 'fuzzy_result' do
it "emits a 'result' div with a 'pre' block where certain content is greyed out" do
html_doc(<<-RUBY)
fuzzy_result "hello {FUZZY}fuzz{/FUZZY} face! nice {FUZZY}banana{/FUZZY}\ni am more text!"
RUBY
expect(@html).to loosely_equal(<<-HTML.strip_heredoc)
<div class="result fuzzy-result">
<span>#{I18n.t("captions.fuzzy_result")}</span>
<pre>
hello <span class="fuzzy-lightened">fuzz</span> face! nice <span class="fuzzy-lightened">banana</span>
i am more text!
</pre>
<div class="fuzzy-hint">The greyed-out text may differ and is not important.</div>
</div>
HTML
end
end
describe 'insert' do
it 'renders a stepfile inside another stepfile' do
path = dir 'testing-insert' do
file "outer.step", <<-RUBY.strip_heredoc
div 'hello'
insert 'inner'
insert 'inner'
div 'goodbye'
RUBY
file "_inner.step", <<-RUBY.strip_heredoc
div 'yum'
RUBY
end
outer_path = File.join(path, 'outer.step')
html = step_obj_for(outer_path).to_html
expect(html).to loosely_equal(<<-HTML.strip_heredoc)
<div>hello</div>
<div>yum</div>
<div>yum</div>
<div>goodbye</div>
HTML
end
end
end