rainforest-cli 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile +0 -1
- data/README.md +78 -10
- data/lib/rainforest/cli.rb +8 -4
- data/lib/rainforest/cli/exporter.rb +86 -0
- data/lib/rainforest/cli/options.rb +11 -1
- data/lib/rainforest/cli/runner.rb +1 -0
- data/lib/rainforest/cli/sites.rb +35 -0
- data/lib/rainforest/cli/test_files.rb +44 -4
- data/lib/rainforest/cli/test_parser.rb +51 -17
- data/lib/rainforest/cli/uploader.rb +4 -2
- data/lib/rainforest/cli/validator.rb +1 -1
- data/lib/rainforest/cli/version.rb +1 -1
- data/spec/cli_spec.rb +13 -0
- data/spec/csv_importer_spec.rb +0 -3
- data/spec/exporter_spec.rb +140 -0
- data/spec/options_spec.rb +5 -0
- data/spec/rainforest-example/example_test.rfml +1 -0
- data/spec/redirection-examples/no_redirect.rfml +10 -0
- data/spec/redirection-examples/no_redirect_embedded.rfml +10 -0
- data/spec/redirection-examples/redirect.rfml +10 -0
- data/spec/redirection-examples/redirect_embedded.rfml +10 -0
- data/spec/redirection-examples/wrong_redirect.rfml +10 -0
- data/spec/redirection-examples/wrong_redirect_embedded.rfml +10 -0
- data/spec/redirection-examples/wrong_redirect_spacing.rfml +11 -0
- data/spec/sites_spec.rb +74 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/test_files_spec.rb +6 -4
- data/spec/test_parser_spec.rb +86 -0
- data/spec/uploader_spec.rb +3 -5
- metadata +24 -4
- data/circle.yml +0 -3
- data/lib/rainforest/cli/test_importer.rb +0 -182
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module RainforestCli::TestParser
|
3
|
-
class EmbeddedTest < Struct.new(:rfml_id)
|
3
|
+
class EmbeddedTest < Struct.new(:rfml_id, :redirect)
|
4
4
|
def type
|
5
5
|
:test
|
6
6
|
end
|
@@ -9,10 +9,14 @@ module RainforestCli::TestParser
|
|
9
9
|
"--> embed: #{rfml_id}"
|
10
10
|
end
|
11
11
|
|
12
|
+
def redirection
|
13
|
+
redirect || 'true'
|
14
|
+
end
|
15
|
+
|
12
16
|
def to_element(primary_key_id)
|
13
17
|
{
|
14
18
|
type: 'test',
|
15
|
-
redirection:
|
19
|
+
redirection: redirection,
|
16
20
|
element: {
|
17
21
|
id: primary_key_id
|
18
22
|
}
|
@@ -20,11 +24,15 @@ module RainforestCli::TestParser
|
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
|
-
class Step < Struct.new(:action, :response)
|
27
|
+
class Step < Struct.new(:action, :response, :redirect)
|
24
28
|
def type
|
25
29
|
:step
|
26
30
|
end
|
27
31
|
|
32
|
+
def redirection
|
33
|
+
redirect || 'true'
|
34
|
+
end
|
35
|
+
|
28
36
|
def to_s
|
29
37
|
"#{action} --> #{response}"
|
30
38
|
end
|
@@ -32,7 +40,7 @@ module RainforestCli::TestParser
|
|
32
40
|
def to_element
|
33
41
|
{
|
34
42
|
type: 'step',
|
35
|
-
redirection:
|
43
|
+
redirection: redirection,
|
36
44
|
element: {
|
37
45
|
action: action,
|
38
46
|
response: response
|
@@ -41,7 +49,18 @@ module RainforestCli::TestParser
|
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
44
|
-
class Test < Struct.new(
|
52
|
+
class Test < Struct.new(
|
53
|
+
:file_name,
|
54
|
+
:rfml_id,
|
55
|
+
:description,
|
56
|
+
:title,
|
57
|
+
:start_uri,
|
58
|
+
:site_id,
|
59
|
+
:steps,
|
60
|
+
:errors,
|
61
|
+
:tags,
|
62
|
+
:browsers
|
63
|
+
)
|
45
64
|
def embedded_ids
|
46
65
|
steps.inject([]) { |embeds, step| step.type == :test ? embeds + [step.rfml_id] : embeds }
|
47
66
|
end
|
@@ -68,11 +87,13 @@ module RainforestCli::TestParser
|
|
68
87
|
@test.browsers = []
|
69
88
|
end
|
70
89
|
|
71
|
-
|
90
|
+
TEST_DATA_FIELDS = [:start_uri, :title, :tags, :site_id].freeze
|
91
|
+
STEP_DATA_FIELDS = [:redirect].freeze
|
72
92
|
CSV_FIELDS = [:tags, :browsers].freeze
|
73
93
|
|
74
94
|
def process
|
75
|
-
|
95
|
+
step_scratch = []
|
96
|
+
step_settings_scratch = {}
|
76
97
|
|
77
98
|
text.lines.each_with_index do |line, line_no|
|
78
99
|
line = line.chomp
|
@@ -85,7 +106,16 @@ module RainforestCli::TestParser
|
|
85
106
|
# comment, store in description
|
86
107
|
@test.description += line[1..-1] + "\n"
|
87
108
|
|
88
|
-
|
109
|
+
if line[1..-1].strip[0..8] == 'redirect:'
|
110
|
+
value = line[1..-1].split(' ')[1..-1].join(' ').strip
|
111
|
+
if %(true false).include?(value)
|
112
|
+
step_settings_scratch[:redirect] = value
|
113
|
+
else
|
114
|
+
@test.errors[line_no] = Error.new(line_no, 'Redirection value must be true or false')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
(CSV_FIELDS + TEST_DATA_FIELDS).each do |field|
|
89
119
|
next unless line[1..-1].strip[0..(field.length)] == "#{field}:"
|
90
120
|
|
91
121
|
# extract just the text of the field
|
@@ -97,31 +127,35 @@ module RainforestCli::TestParser
|
|
97
127
|
end
|
98
128
|
end
|
99
129
|
|
100
|
-
elsif
|
130
|
+
elsif step_scratch.count == 0 && line.strip != ''
|
101
131
|
if line[0] == '-'
|
102
|
-
@test.steps << EmbeddedTest.new(line[1..-1].strip)
|
132
|
+
@test.steps << EmbeddedTest.new(line[1..-1].strip, step_settings_scratch[:redirect])
|
133
|
+
step_settings_scratch = {}
|
103
134
|
else
|
104
|
-
|
135
|
+
step_scratch << line.strip
|
105
136
|
end
|
106
137
|
|
107
|
-
elsif
|
138
|
+
elsif step_scratch.count == 1
|
108
139
|
if line.strip == ''
|
109
140
|
@test.errors[line_no] = Error.new(line_no, 'Missing question')
|
110
141
|
elsif !line.include?('?')
|
111
142
|
@test.errors[line_no] = Error.new(line_no, 'Missing ?')
|
112
143
|
else
|
113
|
-
|
144
|
+
step_scratch << line.strip
|
114
145
|
end
|
115
146
|
|
147
|
+
elsif line.strip.empty? && step_settings_scratch.any?
|
148
|
+
@test.errors[line_no] = Error.new(line_no, 'Extra space between step attributes and step content.')
|
116
149
|
end
|
117
150
|
|
118
151
|
if @test.errors.has_key?(line_no)
|
119
|
-
|
152
|
+
step_scratch = []
|
120
153
|
end
|
121
154
|
|
122
|
-
if
|
123
|
-
@test.steps << Step.new(
|
124
|
-
|
155
|
+
if step_scratch.count == 2
|
156
|
+
@test.steps << Step.new(step_scratch[0], step_scratch[1], step_settings_scratch[:redirect])
|
157
|
+
step_scratch = []
|
158
|
+
step_settings_scratch = {}
|
125
159
|
end
|
126
160
|
end
|
127
161
|
|
@@ -7,7 +7,7 @@ class RainforestCli::Uploader
|
|
7
7
|
attr_reader :test_files, :remote_tests, :validator
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
-
@test_files = RainforestCli::TestFiles.new(options
|
10
|
+
@test_files = RainforestCli::TestFiles.new(options)
|
11
11
|
@remote_tests = RainforestCli::RemoteTests.new(options.token)
|
12
12
|
@validator = RainforestCli::Validator.new(options, test_files, remote_tests)
|
13
13
|
end
|
@@ -51,7 +51,8 @@ class RainforestCli::Uploader
|
|
51
51
|
test_obj = {
|
52
52
|
title: rfml_test.title,
|
53
53
|
start_uri: rfml_test.start_uri,
|
54
|
-
rfml_id: rfml_test.rfml_id
|
54
|
+
rfml_id: rfml_test.rfml_id,
|
55
|
+
source: 'rainforest-cli'
|
55
56
|
}
|
56
57
|
rf_test = Rainforest::Test.create(test_obj)
|
57
58
|
|
@@ -82,6 +83,7 @@ class RainforestCli::Uploader
|
|
82
83
|
test_obj = {
|
83
84
|
start_uri: rfml_test.start_uri || '/',
|
84
85
|
title: rfml_test.title,
|
86
|
+
site_id: rfml_test.site_id,
|
85
87
|
description: rfml_test.description,
|
86
88
|
source: 'rainforest-cli',
|
87
89
|
tags: rfml_test.tags.uniq,
|
@@ -7,7 +7,7 @@ class RainforestCli::Validator
|
|
7
7
|
attr_reader :local_tests, :remote_tests
|
8
8
|
|
9
9
|
def initialize(options, local_tests = nil, remote_tests = nil)
|
10
|
-
@local_tests = local_tests || RainforestCli::TestFiles.new(options
|
10
|
+
@local_tests = local_tests || RainforestCli::TestFiles.new(options)
|
11
11
|
@remote_tests = remote_tests || RainforestCli::RemoteTests.new(options.token)
|
12
12
|
end
|
13
13
|
|
data/spec/cli_spec.rb
CHANGED
@@ -173,6 +173,19 @@ describe RainforestCli do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
context 'with token from env' do
|
177
|
+
let(:params) { %w(run) }
|
178
|
+
|
179
|
+
it 'starts the run without error' do
|
180
|
+
expect_any_instance_of(http_client).to receive(:post).with(
|
181
|
+
'/runs',
|
182
|
+
{ tests: [] }
|
183
|
+
).and_return({})
|
184
|
+
allow(ENV).to receive(:[]).with('RAINFOREST_API_TOKEN').and_return('x')
|
185
|
+
described_class.start(params)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
176
189
|
context 'a simple run' do
|
177
190
|
before do
|
178
191
|
allow_any_instance_of(http_client).to receive(:post).and_return('id' => 1)
|
data/spec/csv_importer_spec.rb
CHANGED
@@ -4,14 +4,11 @@ describe RainforestCli::CSVImporter do
|
|
4
4
|
|
5
5
|
describe '.import' do
|
6
6
|
subject { described_class.new('variables', csv_file, 'abc123') }
|
7
|
-
let(:progressbar_mock) { double('ProgressBar') }
|
8
7
|
|
9
8
|
before do
|
10
9
|
# suppress output in terminal
|
11
10
|
allow_any_instance_of(described_class).to receive(:print)
|
12
11
|
allow_any_instance_of(described_class).to receive(:puts)
|
13
|
-
allow(ProgressBar).to receive(:create).and_return(progressbar_mock)
|
14
|
-
allow(progressbar_mock).to receive(:increment)
|
15
12
|
end
|
16
13
|
|
17
14
|
let(:columns) { %w(email pass) }
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
describe RainforestCli::Exporter do
|
3
|
+
let(:options) do
|
4
|
+
instance_double('RainforestCli::Options', token: nil, test_folder: nil, debug: nil, embed_tests: nil, tests: [])
|
5
|
+
end
|
6
|
+
subject { described_class.new(options) }
|
7
|
+
|
8
|
+
describe '#export' do
|
9
|
+
# Collect everything printed to file in an array-like file double object
|
10
|
+
class FileDouble < Array
|
11
|
+
alias_method :puts, :push
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:file) { FileDouble.new }
|
15
|
+
let(:tests) { [Rainforest::Test.new(id: 123, title: 'Test title')] }
|
16
|
+
let(:embedded_rfml_id) { 'embedded_test_rfml_id' }
|
17
|
+
let(:embedded_test) do
|
18
|
+
{
|
19
|
+
rfml_id: embedded_rfml_id,
|
20
|
+
elements: [
|
21
|
+
{
|
22
|
+
type: 'step',
|
23
|
+
element: {
|
24
|
+
action: 'Embedded Action',
|
25
|
+
response: 'Embedded Response'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
let(:single_test) do
|
32
|
+
Rainforest::Test.new(
|
33
|
+
{
|
34
|
+
id: 123,
|
35
|
+
title: 'Test title',
|
36
|
+
start_uri: '/uri',
|
37
|
+
tags: ['foo', 'bar'],
|
38
|
+
browsers: [
|
39
|
+
{
|
40
|
+
name: 'chrome',
|
41
|
+
state: 'enabled'
|
42
|
+
},
|
43
|
+
{
|
44
|
+
name: 'safari',
|
45
|
+
state: 'enabled'
|
46
|
+
},
|
47
|
+
{
|
48
|
+
name: 'firefox',
|
49
|
+
state: 'disabled'
|
50
|
+
}
|
51
|
+
],
|
52
|
+
elements: [
|
53
|
+
{
|
54
|
+
type: 'step',
|
55
|
+
element: {
|
56
|
+
action: 'Step Action',
|
57
|
+
response: 'Step Response'
|
58
|
+
}
|
59
|
+
},
|
60
|
+
{
|
61
|
+
type: 'test',
|
62
|
+
element: embedded_test
|
63
|
+
}
|
64
|
+
]
|
65
|
+
}
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
before do
|
70
|
+
allow(File).to receive(:open) do |_file_name, _, &blk|
|
71
|
+
blk.call(file)
|
72
|
+
end
|
73
|
+
|
74
|
+
allow_any_instance_of(RainforestCli::TestFiles).to receive(:create_file).and_return('file_name')
|
75
|
+
allow(File).to receive(:truncate)
|
76
|
+
|
77
|
+
allow(Rainforest::Test).to receive(:all).and_return(tests)
|
78
|
+
allow(Rainforest::Test).to receive(:retrieve).and_return(single_test)
|
79
|
+
|
80
|
+
subject.export
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'prints an action and response for a step' do
|
84
|
+
expect(file).to include('Step Action')
|
85
|
+
expect(file).to include('Step Response')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'prints embedded steps' do
|
89
|
+
expect(file).to include('Embedded Action')
|
90
|
+
expect(file).to include('Embedded Response')
|
91
|
+
expect(file).to_not include("- #{embedded_rfml_id}")
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'print enabled browsers only' do
|
95
|
+
comments = file[0]
|
96
|
+
expect(comments).to include('chrome')
|
97
|
+
expect(comments).to include('safari')
|
98
|
+
expect(comments).to_not include('firefox')
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'with embed-tests flag' do
|
102
|
+
let(:options) do
|
103
|
+
instance_double(
|
104
|
+
'RainforestCli::Options',
|
105
|
+
token: nil, test_folder: nil,
|
106
|
+
debug: nil, embed_tests: true, tests: []
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'prints an embedded test rfml id rather than the steps' do
|
111
|
+
expect(file).to include("- #{embedded_rfml_id}")
|
112
|
+
expect(file).to_not include('Embedded Action')
|
113
|
+
expect(file).to_not include('Embedded Response')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with specific tests' do
|
118
|
+
let(:tests) { (123..127).to_a }
|
119
|
+
let(:options) do
|
120
|
+
instance_double(
|
121
|
+
'RainforestCli::Options',
|
122
|
+
token: nil, test_folder: nil, debug: nil,
|
123
|
+
embed_tests: nil, tests: tests
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'gets specific tests instead of all' do
|
128
|
+
expect(Rainforest::Test).to receive(:retrieve).exactly(tests.length).times
|
129
|
+
expect(Rainforest::Test).to receive(:all).exactly(0).times
|
130
|
+
subject.export
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'opens correct number of files' do
|
134
|
+
expect(File).to receive(:open).exactly(tests.length).times
|
135
|
+
expect_any_instance_of(RainforestCli::TestFiles).to receive(:create_file).exactly(tests.length).times
|
136
|
+
subject.export
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/spec/options_spec.rb
CHANGED
@@ -19,6 +19,11 @@ describe RainforestCli::OptionParser do
|
|
19
19
|
its(:import_name) { should == 'some_name' }
|
20
20
|
end
|
21
21
|
|
22
|
+
context 'app_source_url' do
|
23
|
+
let(:args) { ['--app-source-url', 'some_app'] }
|
24
|
+
its(:app_source_url) { should == 'some_app' }
|
25
|
+
end
|
26
|
+
|
22
27
|
context 'run all tests' do
|
23
28
|
let(:args) { ['run', 'all'] }
|
24
29
|
its(:tests) { should == ['all']}
|