forked from railsbridge/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_spec.rb
130 lines (112 loc) · 3.41 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
here = File.expand_path File.dirname(__FILE__)
require "#{here}/spec_helper"
require "step_page"
describe Step do
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
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).gsub("\n", '')
<div class="step" title="hello">
<h1>#{checkbox_html}<span class="prefix">Step 1: </span>hello</h1>
</div>
HTML
assert { html == expected }
end
it "puts titles in based on step names" do
steps = html_doc.css(".step")
assert { steps.first["title"] == "hello" }
assert { steps[1]["title"] == "goodbye" }
end
it "puts anchors in based on step numbers" do
steps = html_doc.css(".step")
steps.each_with_index do |step, i|
assert { step.previous }
assert { to_html(step.previous) == "<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"]}
assert { names == ["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
titles = html_doc.css('.step').map{|div| div["title"]}
assert { titles = ["breakfast", "cereal", "eggs", "lunch", "salad", "sandwich"] }
anchors = html_doc.css("a")
names = anchors.map{|a| a["name"]}
assert { names == ["step1", "step1-1", "step1-2", "step2", "step2-1", "step2-2"] }
end
describe 'link' do
it "passes in a back parameter, so the following page can come back here" 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[title=breakfast] a.link").first
hash = URI.escape '#'
assert { a["href"] == "choose_breakfast?back=hello#{hash}step1" }
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
assert { @html == "<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
assert { @html == "<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
assert { @html == "<div class=\"console\"><span>#{Step::TERMINAL_CAPTION}</span><pre>echo 'hi'</pre></div>" }
end
end
describe 'result' do
it "emits a 'result' div with a 'pre' block" do
html_doc(<<-RUBY)
result "hi"
RUBY
assert { @html == "<div class=\"result\"><span>#{Step::RESULT_CAPTION}</span><pre>hi</pre></div>" }
end
end
end