rainforest-cli 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +62 -9
- data/examples/inline_files.md +43 -0
- data/lib/rainforest_cli/deleter.rb +1 -1
- data/lib/rainforest_cli/exporter.rb +21 -20
- data/lib/rainforest_cli/http_client.rb +5 -0
- data/lib/rainforest_cli/options.rb +2 -2
- data/lib/rainforest_cli/remote_tests.rb +22 -15
- data/lib/rainforest_cli/test_files.rb +2 -0
- data/lib/rainforest_cli/uploader.rb +1 -1
- data/lib/rainforest_cli/validator.rb +6 -2
- data/lib/rainforest_cli/version.rb +1 -1
- data/spec/rainforest_cli/exporter_spec.rb +71 -56
- data/spec/rainforest_cli/options_spec.rb +1 -1
- data/spec/rainforest_cli/remote_tests_spec.rb +69 -9
- data/spec/rainforest_cli/validator_spec.rb +9 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 913823c8a483a43079a1d4847066e83790b00a77
|
4
|
+
data.tar.gz: 9fca3e86e02723dfb7d405b4866182948dc89f1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de68e1c0a84cceb73a6b5b800cc36b138722a5085f415035eded818e42a24b53e63edfd043242a16dc22e0aceffd4752e2c8b265237113b8fde7a63c9318fdbd
|
7
|
+
data.tar.gz: 4bd09d4ef56dc31c0364a383636418b8cfc6680ef445ad8f2e1ff48fb0b77b45b8ad953c295f77952fca8acf5ed1baabf110b15d0437561fb35b815e8e08744b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Rainforest CLI Changelog
|
2
2
|
|
3
|
+
## 1.8.0 - 19th August 2016
|
4
|
+
- Filter RFML test downloads with `rainforest export` using `--tag`, `--folder`, and `--site-id` flags.
|
5
|
+
(5826000fddeb152dc1e2c8ad4baf04cdc0dd2001, @epaulet)
|
6
|
+
|
3
7
|
## 1.7.0 - 8th August 2016
|
4
8
|
- New run flag: `--wait` for hooking into existing run instead of starting a new one.
|
5
9
|
(77df41bf79b8635fb8c2d8a93968f975db092c69, @shosti)
|
data/README.md
CHANGED
@@ -100,6 +100,12 @@ Export all tests from Rainforest
|
|
100
100
|
rainforest export
|
101
101
|
```
|
102
102
|
|
103
|
+
Export tests filtered by tags, site, and smart folder
|
104
|
+
|
105
|
+
```bash
|
106
|
+
rainforest export --tag foo --tag bar --site-id 123 --folder 456
|
107
|
+
```
|
108
|
+
|
103
109
|
#### Viewing Account Specific Information
|
104
110
|
|
105
111
|
See a list of all of your sites and their IDs
|
@@ -182,12 +188,8 @@ tests and the first step of a test.
|
|
182
188
|
- `EMBEDDED TEST RFML ID` - Embed the steps of another test within the current test
|
183
189
|
using the embedded test's RFML ID.
|
184
190
|
|
185
|
-
|
186
|
-
|
187
|
-
- `{{ file.screenshot(RELATIVE_PATH) }}` will embed screenshot found at RELATIVE_PATH
|
188
|
-
which is a path to the screenshot relative to the RFML file.
|
189
|
-
- `{{ file.download(RELATIVE_PATH) }}` will embed downloadable file link found at RELATIVE_PATH
|
190
|
-
which is a path to the downloadable file relative to the RFML file.
|
191
|
+
For more information on embedding inline screenshots and file downloads,
|
192
|
+
[see our examples](./examples/inline_files.md)
|
191
193
|
|
192
194
|
For more information on test writing, please visit our [documentation](http://support.rainforestqa.com/hc/en-us/sections/200585603-Writing-Tests).
|
193
195
|
|
@@ -195,9 +197,9 @@ For more information on test writing, please visit our [documentation](http://su
|
|
195
197
|
|
196
198
|
Popular command line options are:
|
197
199
|
- `--browsers ie8` or `--browsers ie8,chrome` - specify the browsers you wish to run against. This overrides the test own settings. Valid browsers can be found in your account settings.
|
198
|
-
- `--tag
|
199
|
-
- `--site-id` -
|
200
|
-
- `--folder ID` -
|
200
|
+
- `--tag TAG_NAME` - filter tests by tag. Can be used multiple times for filtering by multiple tags.
|
201
|
+
- `--site-id SITE_ID` - filter tests by a specific site. You can see a list of your site IDs with `rainforest sites`.
|
202
|
+
- `--folder ID` - filter tests in specified folder.
|
201
203
|
- `--environment-id` - run your tests using this environment. Otherwise it will use your default environment
|
202
204
|
- `--conflict OPTION` - use the `abort` option to abort any runs in progress in the same environment as your new run. use the `abort-all` option to abort all runs in progress.
|
203
205
|
- `--fg` - results in the foreground - rainforest-cli will not return until the run is complete. This is what you want to make the build pass / fail dependent on rainforest results
|
@@ -216,6 +218,57 @@ api to construct a junit report. This is useful to track tests in CI such as Je
|
|
216
218
|
- `--import-variable-name NAME` - Use with `run` and `import-variable-csv-file` to upload
|
217
219
|
new tabular variable values before your run to specify the name of your tabular variable.
|
218
220
|
|
221
|
+
###Site-ID
|
222
|
+
Only run tests for a specific site. Get in touch with us for help on getting that you site id if you are unable to.
|
223
|
+
|
224
|
+
<pre>--site-id <b>ID</b></pre>
|
225
|
+
|
226
|
+
###Folder-ID
|
227
|
+
Run tests in specified folder.
|
228
|
+
<pre>--folder <b>ID</b></pre>
|
229
|
+
|
230
|
+
###Environment-ID
|
231
|
+
run your tests using this environment. Otherwise it will use your default environment
|
232
|
+
<pre>--environment-id <b>ID</b></pre>
|
233
|
+
|
234
|
+
###Crowd
|
235
|
+
<pre>--crowd [<b>default</b>|<b>on_premise_crowd</b>]</pre>
|
236
|
+
|
237
|
+
###Conflict
|
238
|
+
Use the abort option to abort any runs in progress in the same environment as your new run. use the abort-all option to abort all runs in progress.
|
239
|
+
<pre>--conflict <b>option</b></pre> </pre>
|
240
|
+
|
241
|
+
###Foreground
|
242
|
+
Results in the foreground - rainforest-cli will not return until the run is complete. This is what you want to make the build pass / fail dependent on rainforest results
|
243
|
+
<pre>--fg</pre>
|
244
|
+
|
245
|
+
###Wait
|
246
|
+
Wait for an existing run to finish instead of starting a new one, and exit with a non-0 code if the run fails. rainforest-cli will exit immediately if the run is already complete.
|
247
|
+
<pre>--wait <b>RUN_ID</b></pre>
|
248
|
+
|
249
|
+
###Fail-fast
|
250
|
+
fail the build as soon as the first failed result comes in. If you don't pass this it will wait until 100% of the run is done. Use with --fg.
|
251
|
+
<pre>--fail-fast</pre>
|
252
|
+
###Custom URL
|
253
|
+
|
254
|
+
use a custom url for this run. Example use case: an ad-hoc QA environment with Fourchette. You will need to specify a site_id too for this to work. Note that we will be creating a new environment for this particular run.
|
255
|
+
<pre>--custom-url</pre>
|
256
|
+
|
257
|
+
###Git-trigger
|
258
|
+
only trigger a run when the last commit (for a git repo in the current working directory) has contains @rainforest and a list of one or more tags. E.g. "Fix checkout process. @rainforest #checkout" would trigger a run for everything tagged checkout. This over-rides --tag and any tests specified. If no @rainforest is detected it will exit 0.
|
259
|
+
<pre>--git-trigger</pre>
|
260
|
+
|
261
|
+
###Description "CI automatic run"
|
262
|
+
add an arbitrary description for the run.
|
263
|
+
<pre>--description "CI automatic run"</pre>
|
264
|
+
|
265
|
+
###Embed-tests
|
266
|
+
Use with rainforest export to export your tests without extracting the steps of an embedded test.
|
267
|
+
<pre>--embed-tests</pre>
|
268
|
+
|
269
|
+
###Test-folder
|
270
|
+
Use with rainforest [new, upload, export]. If this option is not provided, rainforest-cli will, in the case of 'new' create a directory, or in the case of 'upload' and 'export' use the directory, at the default path ./spec/rainforest/.
|
271
|
+
<pre>--test-folder /path/to/directory</pre>
|
219
272
|
|
220
273
|
#### Specifying Test IDs
|
221
274
|
Any integers input as arguments in the command line arguments are treated as
|
@@ -0,0 +1,43 @@
|
|
1
|
+
## Embedding Files Inline
|
2
|
+
|
3
|
+
You can embed inline screenshots and file download links directly into RFML by simply supplying the correct step variable and file path in your step.
|
4
|
+
|
5
|
+
The file paths used by `file.screenshot` and `file.download` are _relative to the RFML file_. **Your
|
6
|
+
file must also be checked into version control.** This ensures that everyone always has the most
|
7
|
+
up to date file when using the `upload` command.
|
8
|
+
|
9
|
+
#### Inline Screenshots Example
|
10
|
+
|
11
|
+
In the example below if your RFML test is located at `~/Desktop/my_test_repo/my_awesome_test.rfml`, then the screenshot in question would be located at `~/Desktop/my_test_repo/test_screenshot.png`.
|
12
|
+
|
13
|
+
```
|
14
|
+
#! my_rfml_id
|
15
|
+
# title: My Awesome Test
|
16
|
+
# start_uri: /
|
17
|
+
#
|
18
|
+
|
19
|
+
Click on the button in this image {{ file.screenshot(./test_screenshot.png) }}.
|
20
|
+
Did you go to a login page?
|
21
|
+
```
|
22
|
+
|
23
|
+
#### Inline Downloadable File Example
|
24
|
+
In the example below if your RFML test is located at `~/Desktop/my_test_repo/my_awesome_test.rfml`, then the file in question would be located at `~/Desktop/my_test_repo/test_file.txt`.
|
25
|
+
|
26
|
+
```
|
27
|
+
#! my_rfml_id
|
28
|
+
# title: My Awesome Test
|
29
|
+
# start_uri: /
|
30
|
+
#
|
31
|
+
|
32
|
+
Click on the button in this image {{ file.download(./test_file.txt) }}.
|
33
|
+
Did you go to a login page?
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
#### Uploading
|
38
|
+
|
39
|
+
Once you have set up your variables, you're done! `rainforest upload` will take care of the rest. You can double check that your uploads were successful but making sure that the file paths were replaced with proper arguments in the dashboard. Proper arguments look similar to the following:
|
40
|
+
|
41
|
+
**Screenshots:** `{{ file.screenshot(2262, WVXkKK) }}`
|
42
|
+
|
43
|
+
**Downloads:** `{{ file.download(2262, WVXkKK, test_screenshot.png) }}`
|
@@ -7,7 +7,7 @@ class RainforestCli::Deleter
|
|
7
7
|
def initialize(options)
|
8
8
|
@file_name = options.file_name
|
9
9
|
@test_files = RainforestCli::TestFiles.new(options)
|
10
|
-
@remote_tests = RainforestCli::RemoteTests.new(options
|
10
|
+
@remote_tests = RainforestCli::RemoteTests.new(options)
|
11
11
|
end
|
12
12
|
|
13
13
|
def delete
|
@@ -1,6 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'securerandom'
|
3
|
-
require 'rainforest'
|
4
2
|
require 'parallel'
|
5
3
|
require 'ruby-progressbar'
|
6
4
|
|
@@ -9,9 +7,8 @@ class RainforestCli::Exporter
|
|
9
7
|
|
10
8
|
def initialize(options)
|
11
9
|
@options = options
|
12
|
-
::Rainforest.api_key = @options.token
|
13
10
|
@test_files = RainforestCli::TestFiles.new(@options)
|
14
|
-
@remote_tests = RainforestCli::RemoteTests.new(@options
|
11
|
+
@remote_tests = RainforestCli::RemoteTests.new(@options)
|
15
12
|
end
|
16
13
|
|
17
14
|
def logger
|
@@ -33,10 +30,10 @@ class RainforestCli::Exporter
|
|
33
30
|
p = ProgressBar.create(title: 'Tests', total: test_ids.count, format: '%a %B %p%% %t')
|
34
31
|
Parallel.each(test_ids, in_threads: threads, finish: lambda { |_item, _i, _result| p.increment }) do |test_id|
|
35
32
|
# Get the full test from the API
|
36
|
-
test =
|
33
|
+
test = http_client.get("/tests/#{test_id}")
|
37
34
|
|
38
35
|
# File name
|
39
|
-
file_name = sprintf('%010d', test
|
36
|
+
file_name = sprintf('%010d', test['id']) + '_' + test['title'].strip.gsub(/[^a-z0-9 ]+/i, '').gsub(/ +/, '_').downcase
|
40
37
|
file_name = test_files.create_file(file_name)
|
41
38
|
File.truncate(file_name, 0)
|
42
39
|
|
@@ -44,7 +41,7 @@ class RainforestCli::Exporter
|
|
44
41
|
file.puts(get_header(test))
|
45
42
|
|
46
43
|
first_step_processed = false
|
47
|
-
test
|
44
|
+
test['elements'].each_with_index do |element, index|
|
48
45
|
first_step_processed = process_element(file, element, index, first_step_processed)
|
49
46
|
end
|
50
47
|
end
|
@@ -54,15 +51,15 @@ class RainforestCli::Exporter
|
|
54
51
|
private
|
55
52
|
|
56
53
|
def process_element(file, element, index, first_step_processed)
|
57
|
-
case element[
|
54
|
+
case element['type']
|
58
55
|
when 'test'
|
59
56
|
if @options.embed_tests
|
60
57
|
file.puts '' unless index == 0
|
61
58
|
# no redirect if an embedded test is the first step
|
62
|
-
file.puts "# redirect: #{element[
|
63
|
-
file.puts "- #{element[
|
59
|
+
file.puts "# redirect: #{element['redirection']}" if index > 0
|
60
|
+
file.puts "- #{element['element']['rfml_id']}"
|
64
61
|
else
|
65
|
-
element[
|
62
|
+
element['element']['elements'].each_with_index do |sub_element, i|
|
66
63
|
# no redirect flags for flattened tests
|
67
64
|
process_element(file, sub_element, i + index, true)
|
68
65
|
end
|
@@ -72,27 +69,31 @@ class RainforestCli::Exporter
|
|
72
69
|
|
73
70
|
# add redirect for first step if preceded by an embedded test
|
74
71
|
if index > 0 && first_step_processed == false
|
75
|
-
file.puts "# redirect: #{element[
|
72
|
+
file.puts "# redirect: #{element['redirection']}"
|
76
73
|
end
|
77
|
-
file.puts element[
|
78
|
-
file.puts element[
|
74
|
+
file.puts element['element']['action'].gsub("\n", ' ').strip
|
75
|
+
file.puts element['element']['response'].gsub("\n", ' ').strip
|
79
76
|
first_step_processed = true
|
80
77
|
else
|
81
|
-
raise "Unknown element type: #{element[
|
78
|
+
raise "Unknown element type: #{element['type']}"
|
82
79
|
end
|
83
80
|
first_step_processed
|
84
81
|
end
|
85
82
|
|
86
83
|
def get_header(test)
|
87
|
-
browsers = test
|
84
|
+
browsers = test['browsers'].map { |b| b['name'] if b['state'] == 'enabled' }.compact
|
88
85
|
<<-EOF
|
89
|
-
#! #{test
|
90
|
-
# title: #{test
|
91
|
-
# start_uri: #{test
|
92
|
-
# tags: #{test
|
86
|
+
#! #{test['rfml_id']}
|
87
|
+
# title: #{test['title']}
|
88
|
+
# start_uri: #{test['start_uri']}
|
89
|
+
# tags: #{test['tags'].join(", ")}
|
93
90
|
# browsers: #{browsers.join(", ")}
|
94
91
|
#
|
95
92
|
|
96
93
|
EOF
|
97
94
|
end
|
95
|
+
|
96
|
+
def http_client
|
97
|
+
RainforestCli.http_client
|
98
|
+
end
|
98
99
|
end
|
@@ -71,11 +71,11 @@ module RainforestCli
|
|
71
71
|
@token = value
|
72
72
|
end
|
73
73
|
|
74
|
-
opts.on('--tag TAG', String, '
|
74
|
+
opts.on('--tag TAG', String, 'Filter your tests by tag') do |value|
|
75
75
|
@tags << value
|
76
76
|
end
|
77
77
|
|
78
|
-
opts.on('--folder ID', '
|
78
|
+
opts.on('--folder ID', Integer, 'Filter for tests in the specified folders') do |value|
|
79
79
|
@folder = value
|
80
80
|
end
|
81
81
|
|
@@ -1,12 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class RainforestCli::RemoteTests
|
3
|
-
def initialize(
|
4
|
-
|
5
|
-
@client = RainforestCli::HttpClient.new token: api_token
|
6
|
-
end
|
7
|
-
|
8
|
-
def api_token_set?
|
9
|
-
!Rainforest.api_key.nil?
|
3
|
+
def initialize(options)
|
4
|
+
@options = options
|
10
5
|
end
|
11
6
|
|
12
7
|
def tests
|
@@ -33,16 +28,10 @@ class RainforestCli::RemoteTests
|
|
33
28
|
primary_key_dictionary
|
34
29
|
end
|
35
30
|
|
36
|
-
private
|
37
|
-
|
38
|
-
def logger
|
39
|
-
RainforestCli.logger
|
40
|
-
end
|
41
|
-
|
42
31
|
def fetch_tests
|
43
|
-
if api_token_set?
|
32
|
+
if http_client.api_token_set?
|
44
33
|
logger.info 'Fetching test data from server...'
|
45
|
-
test_list =
|
34
|
+
test_list = http_client.get('/tests/rfml_ids', filters)
|
46
35
|
logger.info 'Fetch complete.'
|
47
36
|
test_list
|
48
37
|
else
|
@@ -50,4 +39,22 @@ class RainforestCli::RemoteTests
|
|
50
39
|
[]
|
51
40
|
end
|
52
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def filters
|
46
|
+
{}.tap do |f|
|
47
|
+
f[:tags] = @options.tags if @options.tags.any?
|
48
|
+
f[:smart_folder_id] = @options.folder if @options.folder
|
49
|
+
f[:site_id] = @options.site_id if @options.site_id
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def logger
|
54
|
+
RainforestCli.logger
|
55
|
+
end
|
56
|
+
|
57
|
+
def http_client
|
58
|
+
RainforestCli.http_client
|
59
|
+
end
|
53
60
|
end
|
@@ -10,7 +10,7 @@ class RainforestCli::Uploader
|
|
10
10
|
|
11
11
|
def initialize(options)
|
12
12
|
@test_files = RainforestCli::TestFiles.new(options)
|
13
|
-
@remote_tests = RainforestCli::RemoteTests.new(options
|
13
|
+
@remote_tests = RainforestCli::RemoteTests.new(options)
|
14
14
|
@validator = RainforestCli::Validator.new(options, test_files, remote_tests)
|
15
15
|
end
|
16
16
|
|
@@ -8,7 +8,7 @@ class RainforestCli::Validator
|
|
8
8
|
|
9
9
|
def initialize(options, local_tests = nil, remote_tests = nil)
|
10
10
|
@local_tests = local_tests || RainforestCli::TestFiles.new(options)
|
11
|
-
@remote_tests = remote_tests || RainforestCli::RemoteTests.new(options
|
11
|
+
@remote_tests = remote_tests || RainforestCli::RemoteTests.new(options)
|
12
12
|
end
|
13
13
|
|
14
14
|
def validate
|
@@ -19,7 +19,7 @@ class RainforestCli::Validator
|
|
19
19
|
def validate_with_exception!
|
20
20
|
check_test_directory_for_tests!
|
21
21
|
|
22
|
-
unless
|
22
|
+
unless http_client.api_token_set?
|
23
23
|
logger.error API_TOKEN_ERROR
|
24
24
|
exit 2
|
25
25
|
end
|
@@ -182,4 +182,8 @@ class RainforestCli::Validator
|
|
182
182
|
def logger
|
183
183
|
RainforestCli.logger
|
184
184
|
end
|
185
|
+
|
186
|
+
def http_client
|
187
|
+
RainforestCli.http_client
|
188
|
+
end
|
185
189
|
end
|
@@ -8,11 +8,19 @@ describe RainforestCli::Exporter do
|
|
8
8
|
command: nil,
|
9
9
|
debug: nil,
|
10
10
|
embed_tests: nil,
|
11
|
-
tests: []
|
11
|
+
tests: [],
|
12
|
+
tags: [],
|
13
|
+
folder: nil,
|
14
|
+
site_id: nil
|
12
15
|
)
|
13
16
|
end
|
17
|
+
let(:http_client) { instance_double(RainforestCli::HttpClient, api_token_set?: true) }
|
14
18
|
subject { described_class.new(options) }
|
15
19
|
|
20
|
+
before do
|
21
|
+
allow(RainforestCli).to receive(:http_client).and_return(http_client)
|
22
|
+
end
|
23
|
+
|
16
24
|
describe '#export' do
|
17
25
|
# Collect everything printed to file in an array-like file double object
|
18
26
|
class FileDouble < Array
|
@@ -29,63 +37,62 @@ describe RainforestCli::Exporter do
|
|
29
37
|
let(:embedded_rfml_id) { 'embedded_test_rfml_id' }
|
30
38
|
let(:embedded_test) do
|
31
39
|
{
|
32
|
-
rfml_id
|
33
|
-
elements
|
40
|
+
'rfml_id' => embedded_rfml_id,
|
41
|
+
'elements' => [
|
34
42
|
{
|
35
|
-
type
|
36
|
-
element
|
37
|
-
action
|
38
|
-
response
|
39
|
-
}
|
40
|
-
}
|
41
|
-
]
|
43
|
+
'type' => 'step',
|
44
|
+
'element' => {
|
45
|
+
'action' => 'Embedded Action',
|
46
|
+
'response' => 'Embedded Response',
|
47
|
+
},
|
48
|
+
},
|
49
|
+
],
|
42
50
|
}
|
43
51
|
end
|
44
52
|
let(:test_elements) do
|
45
53
|
[
|
46
54
|
{
|
47
|
-
type
|
48
|
-
redirection
|
49
|
-
element
|
55
|
+
'type' => 'test',
|
56
|
+
'redirection' => true,
|
57
|
+
'element' => embedded_test,
|
50
58
|
},
|
51
59
|
{
|
52
|
-
type
|
53
|
-
redirection
|
54
|
-
element
|
55
|
-
action
|
56
|
-
response
|
57
|
-
}
|
60
|
+
'type' => 'step',
|
61
|
+
'redirection' => false,
|
62
|
+
'element' => {
|
63
|
+
'action' => 'Step Action',
|
64
|
+
'response' => 'Step Response',
|
65
|
+
},
|
58
66
|
},
|
59
67
|
{
|
60
|
-
type
|
61
|
-
redirection
|
62
|
-
element
|
68
|
+
'type' => 'test',
|
69
|
+
'redirection' => true,
|
70
|
+
'element' => embedded_test,
|
63
71
|
},
|
64
72
|
{
|
65
|
-
type
|
66
|
-
redirection
|
67
|
-
element
|
68
|
-
action
|
69
|
-
response
|
70
|
-
}
|
71
|
-
}
|
73
|
+
'type' => 'step',
|
74
|
+
'redirection' => false,
|
75
|
+
'element' => {
|
76
|
+
'action' => 'Last step',
|
77
|
+
'response' => 'Last step?',
|
78
|
+
},
|
79
|
+
},
|
72
80
|
]
|
73
81
|
end
|
82
|
+
let(:single_test_id) { 123 }
|
74
83
|
let(:single_test) do
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
}
|
88
|
-
)
|
84
|
+
{
|
85
|
+
'id' => single_test_id,
|
86
|
+
'title' => 'Test title',
|
87
|
+
'start_uri' => '/uri',
|
88
|
+
'tags' => ['foo', 'bar'],
|
89
|
+
'browsers' => [
|
90
|
+
{ 'name' => 'chrome', 'state' => 'enabled' },
|
91
|
+
{ 'name' => 'safari', 'state' => 'enabled' },
|
92
|
+
{ 'name' => 'firefox', 'state' => 'disabled' },
|
93
|
+
],
|
94
|
+
'elements' => test_elements,
|
95
|
+
}
|
89
96
|
end
|
90
97
|
|
91
98
|
before do
|
@@ -96,25 +103,26 @@ describe RainforestCli::Exporter do
|
|
96
103
|
allow_any_instance_of(RainforestCli::TestFiles).to receive(:create_file).and_return('file_name')
|
97
104
|
allow(File).to receive(:truncate)
|
98
105
|
|
99
|
-
|
106
|
+
allow(http_client).to receive(:get).with('/tests/rfml_ids', an_instance_of(Hash))
|
100
107
|
.and_return(tests)
|
101
|
-
allow(
|
102
|
-
|
103
|
-
subject.export
|
108
|
+
allow(http_client).to receive(:get).with("/tests/#{single_test_id}").and_return(single_test)
|
104
109
|
end
|
105
110
|
|
106
111
|
it 'prints an action and response for a step' do
|
112
|
+
subject.export
|
107
113
|
expect(file).to include('Step Action')
|
108
114
|
expect(file).to include('Step Response')
|
109
115
|
end
|
110
116
|
|
111
117
|
it 'prints embedded steps' do
|
118
|
+
subject.export
|
112
119
|
expect(file).to include('Embedded Action')
|
113
120
|
expect(file).to include('Embedded Response')
|
114
121
|
expect(file).to_not include("- #{embedded_rfml_id}")
|
115
122
|
end
|
116
123
|
|
117
124
|
it 'print enabled browsers only' do
|
125
|
+
subject.export
|
118
126
|
comments = file[0]
|
119
127
|
expect(comments).to include('chrome')
|
120
128
|
expect(comments).to include('safari')
|
@@ -129,16 +137,17 @@ describe RainforestCli::Exporter do
|
|
129
137
|
let(:test_elements) do
|
130
138
|
[
|
131
139
|
{
|
132
|
-
type
|
133
|
-
element
|
134
|
-
action
|
135
|
-
response
|
136
|
-
}
|
137
|
-
}
|
140
|
+
'type' => 'step',
|
141
|
+
'element' => {
|
142
|
+
'action' => action,
|
143
|
+
'response' => response,
|
144
|
+
},
|
145
|
+
},
|
138
146
|
]
|
139
147
|
end
|
140
148
|
|
141
149
|
it 'removes the newlines' do
|
150
|
+
subject.export
|
142
151
|
expect(file).to include(expected_action)
|
143
152
|
expect(file).to include(expected_response)
|
144
153
|
end
|
@@ -148,18 +157,20 @@ describe RainforestCli::Exporter do
|
|
148
157
|
let(:options) do
|
149
158
|
instance_double(
|
150
159
|
'RainforestCli::Options',
|
151
|
-
token: 'token', test_folder: nil, command: nil,
|
152
|
-
|
160
|
+
token: 'token', test_folder: nil, command: nil, debug: nil, embed_tests: true,
|
161
|
+
tests: [], tags: [], folder: nil, site_id: nil
|
153
162
|
)
|
154
163
|
end
|
155
164
|
|
156
165
|
it 'prints an embedded test rfml id' do
|
166
|
+
subject.export
|
157
167
|
expect(file).to include("- #{embedded_rfml_id}")
|
158
168
|
expect(file_str).to_not include('Embedded Action')
|
159
169
|
expect(file_str).to_not include('Embedded Response')
|
160
170
|
end
|
161
171
|
|
162
172
|
it 'prints the redirects in the correct location' do
|
173
|
+
subject.export
|
163
174
|
# the first embedded test should not have a redirect before it
|
164
175
|
expect(file_str.scan(/# redirect: true\n- #{embedded_rfml_id}/).count).to eq(1)
|
165
176
|
|
@@ -182,8 +193,12 @@ describe RainforestCli::Exporter do
|
|
182
193
|
)
|
183
194
|
end
|
184
195
|
|
196
|
+
before do
|
197
|
+
allow(http_client).to receive(:get).with(/\/tests\/\d+/).and_return(single_test)
|
198
|
+
end
|
199
|
+
|
185
200
|
it 'gets specific tests instead of all' do
|
186
|
-
expect(
|
201
|
+
expect(http_client).to receive(:get).with(/\/tests\/\d+/).exactly(test_ids.length)
|
187
202
|
expect_any_instance_of(RainforestCli::RemoteTests).to_not receive(:primary_ids)
|
188
203
|
subject.export
|
189
204
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
describe RainforestCli::RemoteTests do
|
3
|
-
|
3
|
+
let(:options) { instance_double('RainforestCli::OptionsParser', tags: [], folder: nil, site_id: nil) }
|
4
|
+
let(:tests) { [] }
|
5
|
+
let(:http_client) { instance_double('RainforestCli::HttpClient', api_token_set?: true) }
|
6
|
+
subject { described_class.new(options) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(RainforestCli).to receive(:http_client).and_return(http_client)
|
10
|
+
allow(http_client).to receive(:get).with('/tests/rfml_ids', an_instance_of(Hash)).and_return(tests)
|
11
|
+
end
|
4
12
|
|
5
13
|
describe '#primary_key_dictionary' do
|
6
14
|
Test = Struct.new(:rfml_id, :id)
|
@@ -10,29 +18,81 @@ describe RainforestCli::RemoteTests do
|
|
10
18
|
let(:test3) { { 'rfml_id' => 'baz', 'id' => 789 } }
|
11
19
|
let(:tests) { [test1, test2, test3] }
|
12
20
|
|
13
|
-
before do
|
14
|
-
allow_any_instance_of(RainforestCli::HttpClient).to receive(:get)
|
15
|
-
.with('/tests/rfml_ids').and_return(tests)
|
16
|
-
end
|
17
|
-
|
18
21
|
it "correctly formats the dictionary's keys and values" do
|
19
22
|
expect(subject.primary_key_dictionary)
|
20
23
|
.to include({
|
21
24
|
test1['rfml_id'] => test1['id'],
|
22
25
|
test2['rfml_id'] => test2['id'],
|
23
|
-
test3['rfml_id'] => test3['id']
|
26
|
+
test3['rfml_id'] => test3['id'],
|
24
27
|
})
|
25
28
|
end
|
26
29
|
|
27
30
|
context 'no api token set' do
|
28
|
-
|
31
|
+
let(:http_client) { instance_double('RainforestCli::HttpClient', api_token_set?: false) }
|
29
32
|
|
30
33
|
it 'does not make an API call but returns an empty dictionary' do
|
31
|
-
|
34
|
+
expect(http_client).to_not receive(:get)
|
32
35
|
dictionary = subject.primary_key_dictionary
|
33
36
|
expect(dictionary).to be_a(Hash)
|
34
37
|
expect(dictionary).to eq({})
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
41
|
+
|
42
|
+
describe '#fetch_tests' do
|
43
|
+
let(:url) { '/tests/rfml_ids' }
|
44
|
+
let(:tags) { ['foo', 'bar'] }
|
45
|
+
let(:smart_folder_id) { 123 }
|
46
|
+
let(:site_id) { 456 }
|
47
|
+
|
48
|
+
context 'with tags option set' do
|
49
|
+
let(:options) { instance_double('RainforestCli::OptionsParser', tags: tags, folder: nil, site_id: nil) }
|
50
|
+
|
51
|
+
it 'uses tags as a request parameter' do
|
52
|
+
expect(http_client).to receive(:get) do |url, params|
|
53
|
+
expect(url).to eq(url)
|
54
|
+
expect(params[:tags]).to eq(tags)
|
55
|
+
end
|
56
|
+
subject.fetch_tests
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with smart folder option set' do
|
61
|
+
let(:options) { instance_double('RainforestCli::OptionsParser', tags: [], folder: smart_folder_id, site_id: nil) }
|
62
|
+
|
63
|
+
it 'uses smart_folder_id as a request parameter' do
|
64
|
+
expect(http_client).to receive(:get) do |url, params|
|
65
|
+
expect(url).to eq(url)
|
66
|
+
expect(params[:smart_folder_id]).to eq(smart_folder_id)
|
67
|
+
end
|
68
|
+
subject.fetch_tests
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with site id set' do
|
73
|
+
let(:options) { instance_double('RainforestCli::OptionsParser', tags: [], folder: nil, site_id: site_id) }
|
74
|
+
|
75
|
+
it 'uses site_id as a request parameter' do
|
76
|
+
expect(http_client).to receive(:get) do |url, params|
|
77
|
+
expect(url).to eq(url)
|
78
|
+
expect(params[:site_id]).to eq(site_id)
|
79
|
+
end
|
80
|
+
subject.fetch_tests
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with all parameters set' do
|
85
|
+
let(:options) { instance_double('RainforestCli::OptionsParser', tags: tags, folder: smart_folder_id, site_id: site_id) }
|
86
|
+
|
87
|
+
it 'uses all request parameters' do
|
88
|
+
expect(http_client).to receive(:get) do |url, params|
|
89
|
+
expect(url).to eq(url)
|
90
|
+
expect(params[:tags]).to eq(tags)
|
91
|
+
expect(params[:smart_folder_id]).to eq(smart_folder_id)
|
92
|
+
expect(params[:site_id]).to eq(site_id)
|
93
|
+
end
|
94
|
+
subject.fetch_tests
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
38
98
|
end
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
describe RainforestCli::Validator do
|
4
4
|
let(:file_path) { File.join(test_directory, correct_file_name) }
|
5
|
+
let(:http_client) { instance_double('RainforestCli::HttpClient', api_token_set?: true) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(RainforestCli).to receive(:http_client).and_return(http_client)
|
9
|
+
end
|
5
10
|
|
6
11
|
def notifies_with_correct_file_name
|
7
12
|
expect(subject).to receive(notification_method)
|
@@ -21,11 +26,11 @@ describe RainforestCli::Validator do
|
|
21
26
|
|
22
27
|
shared_examples 'it detects all the correct errors' do
|
23
28
|
let(:tested_method) { :validate }
|
24
|
-
let(:options) { instance_double('RainforestCli::Options', test_folder: test_directory, token: 'api_token', command: '') }
|
29
|
+
let(:options) { instance_double('RainforestCli::Options', test_folder: test_directory, token: 'api_token', command: '', tags: [], folder: nil, site_id: nil) }
|
25
30
|
subject { described_class.new(options) }
|
26
31
|
|
27
32
|
before do
|
28
|
-
|
33
|
+
allow(http_client).to receive(:get).and_return([])
|
29
34
|
end
|
30
35
|
|
31
36
|
context 'with parsing errors' do
|
@@ -125,7 +130,8 @@ describe RainforestCli::Validator do
|
|
125
130
|
|
126
131
|
context 'without a token option' do
|
127
132
|
let(:test_directory) { File.expand_path(File.dirname(__FILE__) + '/../validation-examples') }
|
128
|
-
let(:options) { instance_double('RainforestCli::Options', test_folder: test_directory,
|
133
|
+
let(:options) { instance_double('RainforestCli::Options', test_folder: test_directory, command: '') }
|
134
|
+
let(:http_client) { instance_double('RainforestCli::HttpClient', api_token_set?: false) }
|
129
135
|
subject { described_class.new(options) }
|
130
136
|
|
131
137
|
it 'validates locally and tells the user to include a token to valid with server tests as well' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainforest-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-08-
|
12
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- README.md
|
189
189
|
- Rakefile
|
190
190
|
- bin/rainforest
|
191
|
+
- examples/inline_files.md
|
191
192
|
- lib/rainforest_cli.rb
|
192
193
|
- lib/rainforest_cli/constants.rb
|
193
194
|
- lib/rainforest_cli/csv_importer.rb
|