-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtutorial_spec.rb
More file actions
85 lines (68 loc) · 2.48 KB
/
tutorial_spec.rb
File metadata and controls
85 lines (68 loc) · 2.48 KB
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
require_relative "tryruby_helpers"
RSpec.describe "Tutorial", type: :feature, js: true do
before :each do
visit "/"
end
languages.each do |language|
describe "in #{language}" do
before :each do
find(:css, "#language-menu-toggle").click
find(:css, %'[data-change-lang="#{language}"]').click
wait_for_language_load(language)
end
dataset = language_dataset(language)
steps = {
1 => {pass: true},
12 => {code: "[12, 47, 35, 1]"},
31 => {pass: true},
32 => {pass: true},
37 => {pass: true},
39 => {pass: true}, # Would need to scroll to the bottom...
40 => {code: ->(i) { i.gsub("(0)", "(1591)") }},
42 => {pass: true},
43 => {code: ->(i) { i.gsub("a = 100", "a == 100") }},
44 => {pass: true}, # TODO: Provide a good answer to this
46 => {pass: true},
47 => {pass: true},
52 => {pass: true},
55 => {pass: true},
56 => {output: /www.ruby-lang.org/}
}
(1..56).each do |step|
data = dataset[step.to_s]
# A simplification to get GitHub Actions passed faster
next if ENV['SIMPLIFIED_RUN'] && (step > 5 && language != 'en' && language != ENV['ADDITIONAL_LANG'])
it "has a working step #{step} (#{data["title"]})" do
find(:css, %'#tryruby-index [value="#{step}"]').select_option
wait_for_updating_to_finish
the_cookie_of_step.should be == step
special = steps[step] || {}
find(:css, "h1").text.should be == data["title"].gsub(" ", " ")
unless special[:pass]
case special[:code]
when Proc
click_button("Copy")
set_code(special[:code].(code))
when String then set_code(special[:code])
when nil then click_button("Copy")
else raise
end
wait_for_execution { click_button("Run") }
case special[:output]
when nil then find_all(:css, ".tryruby-output-green").count.should be >= 1
else special[:output].should be === code(:output)
end
end
unless step == 56
click_button("Next")
the_cookie_of_step.should be == step + 1
end
end
end
it "displays a correct title on the first page of the tutorial" do
page.should have_content(dataset["1"]["title"])
the_cookie_of_step.should be == 1
end
end
end
end