apiaryio 0.9.1 → 0.10.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e6995c7b6279057158a86a019baa4d4b27fdc53
4
- data.tar.gz: 27d6406ab90b3bffb7c4585091c65289c22d64ed
3
+ metadata.gz: 3007546160a6dea1800e9169dcc6c5bf5d7b922a
4
+ data.tar.gz: d680b08d8dfa134439d995f1ebde24b34c68dc51
5
5
  SHA512:
6
- metadata.gz: aa8934e0500a0f9b59db8e6d6768669c69c323ab2d387c0db8dfa11b39d1d7fa9f41d9ae92ca6290a471541027912082ef220bded7bc0ef6db445b40fb475916
7
- data.tar.gz: b9d5a3e3f6d5f32db8d6902d49b1b8cd65b32f22af53fb8d09204eb8592a0585191f0dbce2f2ab6076fd56423b3b7c0ba7896b8ca83c86c19e3ed1772c257a47
6
+ metadata.gz: 8bbd3db0eefbb44e76e8ac31db64cce8808ba707a297c246fbaefd17a46840f97867d288de24e8de25d2020777e1bd07aa8be08801077eda6d8876cfbbb42410
7
+ data.tar.gz: 28e0a1c207101776b32f20c1fda40065cc3ea0e0eceeebd8fb8fa81690468ebb2262bfcf64945276805fbe7634efdfd0f65a220800d45b3d1ab735dc0590d27b
data/.rubocop_todo.yml CHANGED
@@ -10,7 +10,7 @@ Metrics/AbcSize:
10
10
  Max: 33
11
11
 
12
12
  Metrics/ClassLength:
13
- Max: 150 # or whatever ends up being appropriate
13
+ Max: 190 # or whatever ends up being appropriate
14
14
 
15
15
  Metrics/PerceivedComplexity:
16
16
  Max: 12
data/README.md CHANGED
@@ -136,6 +136,7 @@ Options:
136
136
  [--functions=FUNCTIONS] # Path to to the file with functions definitions
137
137
  [--rules=RULES] # Path to to the file with rules definitions - `functions.js` and `rules.json` are loaded if not specified
138
138
  [--full-report], [--no-full-report] # Get passed assertions ass well. Only failed assertions are included to the result by default
139
+ [--json], [--no-json] # Outputs all in json
139
140
 
140
141
  Check API Description Document against styleguide rules (Apiary.io pro plan is required - https://apiary.io/plans )
141
142
 
@@ -2,12 +2,19 @@ Feature: Styleguide apiary.apib on docs.API_NAME.apiary.io
2
2
 
3
3
  # This is integration testing you have to set APIARY_API_KEY
4
4
  @needs_apiary_api_key
5
- Scenario: Styleguide validation
5
+ Scenario: Styleguide validation - pass
6
6
 
7
7
  When I run `apiary styleguide --functions=../../features/support --rules=../../features/support --add=../../features/support --full_report`
8
- Then the output should match /(\"validatorError\": false)/
8
+ Then the output should match /(PASSED)/
9
9
  And the exit status should be 0
10
10
 
11
+ @needs_apiary_api_key
12
+ Scenario: Styleguide validation - fail
13
+
14
+ When I run `apiary styleguide --functions=../../features/support/functions-fail.js --rules=../../features/support --add=../../features/support --full_report`
15
+ Then the output should match /(FAILED)/
16
+ And the exit status should be 1
17
+
11
18
  # This is integration testing you have to set APIARY_API_KEY
12
19
  @needs_apiary_api_key
13
20
  Scenario: Styleguide fetch
@@ -0,0 +1,7 @@
1
+ /*
2
+ @targets: API_Name
3
+ */
4
+
5
+ function validateApiName(apiName) {
6
+ return 'fail';
7
+ };
data/lib/apiary/cli.rb CHANGED
@@ -52,6 +52,7 @@ module Apiary
52
52
  method_option :functions, type: :string, desc: 'Path to to the file with functions definitions'
53
53
  method_option :rules, type: :string, desc: 'Path to to the file with rules definitions - `functions.js` and `rules.json` are loaded if not specified'
54
54
  method_option :full_report, type: :boolean, default: false, desc: 'Get passed assertions ass well. Only failed assertions are included to the result by default'
55
+ method_option :json, type: :boolean, default: false, desc: 'Outputs all in json'
55
56
  def styleguide
56
57
  cmd = Apiary::Command::Styleguide.new options
57
58
  cmd.execute
@@ -30,6 +30,7 @@ module Apiary::Command
30
30
  user_agent: Apiary.user_agent
31
31
  }
32
32
  @options.failedOnly = !@options.full_report
33
+ @options.json
33
34
  end
34
35
 
35
36
  def execute
@@ -83,12 +84,66 @@ module Apiary::Command
83
84
  headers = @options.headers.clone
84
85
  headers[:Authorization] = "Bearer #{token}"
85
86
 
86
- result = call_resource(@options.vk_url, data, headers, :post)
87
+ output call_resource(@options.vk_url, data, headers, :post)
88
+ end
89
+
90
+ def print_output_text(result)
91
+ lines = if result['sourcemapLines']['start'] == result['sourcemapLines']['end']
92
+ "on line #{result['sourcemapLines']['start']}"
93
+ else
94
+ "on lines #{result['sourcemapLines']['start']} - #{result['sourcemapLines']['end']}"
95
+ end
96
+
97
+ if result['result'] == true
98
+ puts " [\u2713] PASSED: #{(result['path'] || '').gsub('-', ' #')} #{lines}"
99
+ else
100
+ puts " [\u274C] FAILED: #{(result['path'] || '').gsub('-', ' #')} #{lines} - `#{result['result']}`"
101
+ end
102
+ end
103
+
104
+ def json_output(json_response)
105
+ puts JSON.pretty_generate json_response
106
+ end
107
+
108
+ def human_output(json_response)
109
+ if json_response.empty?
110
+ puts 'All tests has passed'
111
+ exit 0
112
+ end
113
+
114
+ puts ''
115
+
116
+ at_least_one_failed = false
87
117
 
118
+ json_response.each do |response|
119
+ puts " #{(response['intent'] || response['ruleName'] || response['functionName'])}"
120
+
121
+ (response['results'] || []).each do |result|
122
+ print_output_text result
123
+ at_least_one_failed = true if result['result'] != true
124
+ end
125
+
126
+ puts ''
127
+ end
128
+
129
+ if at_least_one_failed
130
+ exit 1
131
+ else
132
+ exit 0
133
+ end
134
+ end
135
+
136
+ def output(raw_response)
88
137
  begin
89
- puts JSON.pretty_generate(JSON.parse(result))
138
+ json_response = JSON.parse(raw_response)
90
139
  rescue
91
- abort "Error: Can not parse result: #{result}"
140
+ abort "Error: Can not parse result: #{raw_response}"
141
+ end
142
+
143
+ if @options.json
144
+ json_output json_response
145
+ else
146
+ human_output json_response
92
147
  end
93
148
  end
94
149
 
@@ -126,7 +181,6 @@ module Apiary::Command
126
181
  abort "#{message} #{e.message}"
127
182
  end
128
183
  end
129
-
130
184
  response
131
185
  end
132
186
 
@@ -1,3 +1,3 @@
1
1
  module Apiary
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.10.1'.freeze
3
3
  end
@@ -128,15 +128,38 @@ describe Apiary::Command::Styleguide do
128
128
  test_abort(command, 'supportXXZ` not found')
129
129
  end
130
130
 
131
- it 'call command with correct paths' do
131
+ it 'call command with correct options which should fail' do
132
132
  opts = {
133
133
  api_key: 'xxx',
134
- functions: 'features/support',
134
+ functions: 'features/support/functions-fail.js',
135
135
  rules: 'features/support',
136
136
  add: 'features/support',
137
137
  full_report: true
138
138
  }
139
139
 
140
+ command = Apiary::Command::Styleguide.new(opts)
141
+ stub_request(:get, "https://#{command.options.api_host}/styleguide-cli/get-token/").to_return(status: 200, body: '{"jwt":"xxx"}')
142
+ response = '[{"ruleName":"validateApiName","functionName":"validateApiName","target":"API_Name","intent":"validateApiName","code":"function validateApiName(apiName) {\n return \'fail\';\n}","functionComment":"\n @targets: API_Name\n ","allowedPaths":["API_Name"],"ref":["API_Name-0"],"results":[{"validatorError":false,"result":"fail","path":"API_Name-0","data":"test","sourcemap":[[12,7]],"sourcemapLines":{"start":2,"end":2}}]}]'
143
+ stub_request(:post, command.options.vk_url).to_return(status: 200, body: response)
144
+
145
+ expect do
146
+ begin
147
+ command.execute
148
+ rescue SystemExit
149
+ end
150
+ end.to output("\n validateApiName\n [❌] FAILED: API_Name #0 on line 2 - `fail`\n\n").to_stdout
151
+ end
152
+
153
+ it 'call command with correct options and json output' do
154
+ opts = {
155
+ api_key: 'xxx',
156
+ functions: 'features/support',
157
+ rules: 'features/support',
158
+ add: 'features/support',
159
+ full_report: true,
160
+ json: true
161
+ }
162
+
140
163
  command = Apiary::Command::Styleguide.new(opts)
141
164
  stub_request(:get, "https://#{command.options.api_host}/styleguide-cli/get-token/").to_return(status: 200, body: '{"jwt":"xxx"}')
142
165
  stub_request(:post, command.options.vk_url).to_return(status: 200, body: '[]')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiaryio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apiary Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -234,6 +234,7 @@ files:
234
234
  - features/styleguide.feature
235
235
  - features/support/apiary.apib
236
236
  - features/support/env.rb
237
+ - features/support/functions-fail.js
237
238
  - features/support/functions.js
238
239
  - features/support/rules.json
239
240
  - features/version.feature
@@ -288,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
289
  version: '0'
289
290
  requirements: []
290
291
  rubyforge_project:
291
- rubygems_version: 2.5.2
292
+ rubygems_version: 2.5.2.1
292
293
  signing_key:
293
294
  specification_version: 4
294
295
  summary: Apiary.io CLI
@@ -300,6 +301,7 @@ test_files:
300
301
  - features/styleguide.feature
301
302
  - features/support/apiary.apib
302
303
  - features/support/env.rb
304
+ - features/support/functions-fail.js
303
305
  - features/support/functions.js
304
306
  - features/support/rules.json
305
307
  - features/version.feature