cm_quiz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 585a0921ebed80326688cb91ff8013ff6ddc4ed9
4
- data.tar.gz: cd95c080f6df5609da4e8143bf0078a07d6a9ea9
3
+ metadata.gz: 05e2c72f987b0c04158a61993591da384cd1f0e5
4
+ data.tar.gz: 847897a6eab4c72fc4f84f12a4af4a80187b281e
5
5
  SHA512:
6
- metadata.gz: b830953bf369a52a64ea2589ffe8f82e8a27ae969e099879377ddc7053154dc9d4b58ffe42a7da4889951e17191b22aac6c80a447e7a9d2e2551eb59963a8bcb
7
- data.tar.gz: fd20b47a3ba61678153cd8a0c44f935cc70d1565a42716d346aa5f80f3a1695824b6aa319f509aba09492523fb57657ed1b0bb44d361c80195f3f674738ed26c
6
+ metadata.gz: f6e1caeeb432906d67a89bb1d4a8a493e1de93d854d89923e74014602e825de3ec86aa8352f88f9b1bdcce7dfbf42492fea95df20e90c1439467c4249132d60c
7
+ data.tar.gz: 087e45d145073f562af0f6be931ee5b1ecee092c9bc31417521da847292614f398f2318532aa4b436833c7cf61681901f276923317735492ab25371dc1732cb4
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm_quiz (0.0.1)
5
- httparty
6
- rspec
4
+ cm_quiz (0.0.2)
5
+ httparty (~> 0.15.6)
6
+ rspec (~> 3.6)
7
7
  thor (~> 0.19.4)
8
8
 
9
9
  GEM
@@ -52,7 +52,7 @@ PLATFORMS
52
52
  DEPENDENCIES
53
53
  cm_quiz!
54
54
  pry
55
- webmock
55
+ webmock (~> 3.0)
56
56
 
57
57
  BUNDLED WITH
58
58
  1.15.0
data/README.md CHANGED
@@ -1,15 +1,32 @@
1
1
  # cm-quiz
2
+ > A CLI tool to review your CodementorX project
2
3
 
3
- ## How to install
4
+ ## Installation💻
5
+ Make sure you have a working Ruby environment (2.3 or later is required).
4
6
 
7
+ ### Install Ruby using [RVM](https://rvm.io/) (for those with older versions of Ruby)
5
8
  ```sh
6
9
  $ ruby -v
7
- # Make sure your ruby version is at least 2.3.0
10
+ # Make sure your Ruby version is at least 2.3.0, below will demo how to install required Ruby version
8
11
 
12
+ $ curl -sSL https://get.rvm.io | bash -s stable
13
+
14
+ # restart your terminal
15
+
16
+ $ rvm install 2.3.0
17
+ $ rvm use 2.3.0
18
+ ```
19
+
20
+
21
+ ### Install `cm-quiz`
22
+ ```sh
9
23
  $ gem install cm_quiz
10
24
  ```
11
25
 
12
- ## How to use
26
+
27
+ ## Start review your quiz🕵️
13
28
  ```sh
14
- $ cm-quiz test --endpoint=your-test-endpoint.com
15
- ```
29
+ $ cm-quiz test --endpoint=https://your-test-endpoint.com
30
+ ```
31
+
32
+
@@ -15,7 +15,9 @@ module CmQuiz
15
15
  def test
16
16
  endpoint = options[:endpoint]
17
17
  puts "Start test #{endpoint}"
18
+ puts "please wait..."
18
19
  message = CmQuiz::ReviewQuiz.new(endpoint).perform
20
+
19
21
  puts message
20
22
  end
21
23
  end
@@ -26,6 +26,8 @@ module CmQuiz
26
26
 
27
27
  res = @project_api.request(:post, '/ideas', options)
28
28
  JSON.parse(res.body)
29
+ rescue => e
30
+ raise StandardError, "Create test idea failed, reason: #{e.message}"
29
31
  end
30
32
  end
31
33
  end
@@ -22,6 +22,8 @@ module CmQuiz
22
22
  res = @project_api.request(:post, '/users', options)
23
23
  payload = JSON.parse(res.body)
24
24
  [payload['jwt'], payload['refresh_token']]
25
+ rescue => e
26
+ raise StandardError, "Create test user failed, reason: #{e.message}"
25
27
  end
26
28
  end
27
29
  end
@@ -3,6 +3,7 @@ require 'cm_quiz/review_helper'
3
3
  module CmQuiz
4
4
  module Review
5
5
  class BaseReview
6
+ attr_reader :verb, :path, :options
6
7
  include ReviewHelper
7
8
 
8
9
  def perform
@@ -18,6 +19,10 @@ module CmQuiz
18
19
  raise "Method `run` should be implemented on class #{self.class}"
19
20
  end
20
21
 
22
+ def build_test_result(test_case, passed = true, message = nil)
23
+ [test_case, passed, message]
24
+ end
25
+
21
26
  def test_request
22
27
  {
23
28
  verb: @verb,
@@ -30,7 +30,7 @@ module CmQuiz
30
30
  private
31
31
 
32
32
  def send_create_idea_request(jwt:, content:, impact:, ease:, confidence:)
33
- options = {
33
+ @options = {
34
34
  headers: {
35
35
  'x-access-token' => jwt
36
36
  },
@@ -42,7 +42,7 @@ module CmQuiz
42
42
  }
43
43
  }
44
44
 
45
- @project_api.request(@verb, @path, options)
45
+ @project_api.request(@verb, @path, @options)
46
46
  end
47
47
  end
48
48
  end
@@ -27,13 +27,14 @@ module CmQuiz
27
27
  private
28
28
 
29
29
  def send_delete_idea_request(jwt:, idea_id:)
30
- options = {
30
+ @options = {
31
31
  headers: {
32
32
  'x-access-token' => jwt
33
33
  }
34
34
  }
35
35
 
36
- @project_api.request(:delete, "/ideas/#{idea_id}", options)
36
+ @path = "/ideas/#{idea_id}"
37
+ @project_api.request(:delete, @path, @options)
37
38
  end
38
39
 
39
40
  def send_get_ideas_request(jwt:)
@@ -46,18 +46,8 @@ module CmQuiz
46
46
 
47
47
  private
48
48
 
49
- def send_delete_idea_request(jwt:, idea_id:)
50
- options = {
51
- headers: {
52
- 'x-access-token' => jwt
53
- }
54
- }
55
-
56
- @project_api.request(:delete, "/ideas/#{idea_id}", options)
57
- end
58
-
59
49
  def send_get_ideas_request(jwt:, page: 1)
60
- options = {
50
+ @options = {
61
51
  headers: {
62
52
  'x-access-token' => jwt
63
53
  },
@@ -66,7 +56,7 @@ module CmQuiz
66
56
  }
67
57
  }
68
58
 
69
- @project_api.request(@verb, @path, options)
59
+ @project_api.request(@verb, @path, @options)
70
60
  end
71
61
  end
72
62
  end
@@ -30,13 +30,13 @@ module CmQuiz
30
30
  private
31
31
 
32
32
  def send_get_user_info_request(jwt:)
33
- options = {
33
+ @options = {
34
34
  headers: {
35
35
  'x-access-token' => jwt
36
36
  }
37
37
  }
38
38
 
39
- @project_api.request(@verb, @path, options)
39
+ @project_api.request(@verb, @path, @options)
40
40
  end
41
41
  end
42
42
  end
@@ -26,6 +26,8 @@ module CmQuiz
26
26
 
27
27
  expect(payload['jwt'].class).to eq(String), '`jwt` should be string'
28
28
  expect(payload['refresh_token'].class).to eq(String), '`refresh_token` should be string'
29
+ rescue => e
30
+ build_test_result(self.class, false, e.message)
29
31
  end
30
32
 
31
33
  private
@@ -28,7 +28,7 @@ module CmQuiz
28
28
  private
29
29
 
30
30
  def send_sign_up_user_request(email:, name:, password:)
31
- options = {
31
+ @options = {
32
32
  body: {
33
33
  email: email,
34
34
  name: name,
@@ -36,7 +36,7 @@ module CmQuiz
36
36
  }
37
37
  }
38
38
 
39
- @project_api.request(@verb, @path, options)
39
+ @project_api.request(@verb, @path, @options)
40
40
  end
41
41
  end
42
42
  end
@@ -36,20 +36,10 @@ module CmQuiz
36
36
 
37
37
  private
38
38
 
39
- def send_delete_idea_request(jwt:, idea_id:)
40
- options = {
41
- headers: {
42
- 'x-access-token' => jwt
43
- }
44
- }
45
-
46
- @project_api.request(:delete, "/ideas/#{idea_id}", options)
47
- end
48
-
49
39
  def send_update_idea_request(jwt:, idea_id:, content: nil, impact: nil,
50
40
  ease: nil, confidence: nil)
51
41
 
52
- options = {
42
+ @options = {
53
43
  headers: {
54
44
  'x-access-token' => jwt
55
45
  },
@@ -60,8 +50,9 @@ module CmQuiz
60
50
  confidence: confidence
61
51
  }
62
52
  }
53
+ @path = "/ideas/#{idea_id}"
63
54
 
64
- @project_api.request(:put, "/ideas/#{idea_id}", options)
55
+ @project_api.request(:put, @path, @options)
65
56
  end
66
57
 
67
58
  end
@@ -17,9 +17,5 @@ module CmQuiz
17
17
  def be_within(delta)
18
18
  RSpec::Matchers::BuiltIn::BeWithin.new(delta)
19
19
  end
20
-
21
- def build_test_result(test_case, passed = true, message = nil)
22
- [test_case, passed, message]
23
- end
24
20
  end
25
21
  end
@@ -29,11 +29,17 @@ module CmQuiz
29
29
  def build_message(test_results, endpoint)
30
30
  score, failed_results = arrange_results(test_results)
31
31
  example_messages = failed_results.map do |result|
32
- # m = (result[0].to_s + ": " + result[2].to_s)
33
32
  verb = result[0][:verb].upcase
34
33
  path = result[0][:path]
35
34
  options = result[0][:options]
36
- messages = ["#{verb} #{@endpoint}#{path}"]
35
+ passed = result[1]
36
+ messages = ["===#{verb} #{@endpoint}#{path}==="]
37
+ messages << ""
38
+ messages << "HTTP method:"
39
+ messages << verb
40
+ messages << ""
41
+ messages << "Url:"
42
+ messages << "#{@endpoint}#{path}"
37
43
  messages << ""
38
44
  messages << "Request options:"
39
45
  messages << ""
@@ -43,7 +49,7 @@ module CmQuiz
43
49
  messages << ""
44
50
  error_message = result[2].to_s
45
51
  error_message = error_message.truncate(500) + '...' if error_message.size > 500
46
- messages << error_message
52
+ messages << error_message + "\n"
47
53
 
48
54
  messages.join("\n")
49
55
  end
@@ -1,3 +1,3 @@
1
1
  module CmQuiz
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -31,20 +31,7 @@ RSpec.describe CmQuiz::Review::CreateIdea do
31
31
  it "should pass test" do
32
32
  test_result = service.perform
33
33
 
34
- expect(test_result).to eq(["post /ideas", true, nil])
35
- options = {
36
- headers: {
37
- 'x-access-token' => 'jwt'
38
- },
39
- body: {
40
- content: mock_idea[:content],
41
- impact: mock_idea[:impact],
42
- ease: mock_idea[:ease],
43
- confidence: mock_idea[:confidence]
44
- }
45
- }
46
- args = [:post, '/ideas', options]
47
- expect(project_api).to have_received(:request).with(*args)
34
+ assert_test_case(service, test_result)
48
35
  end
49
36
  end
50
37
  end
@@ -34,14 +34,7 @@ RSpec.describe CmQuiz::Review::DeleteIdea do
34
34
  it "should pass test" do
35
35
  test_result = service.perform
36
36
 
37
- expect(test_result).to eq(["delete /ideas/:idea_id", true, nil])
38
- options = {
39
- headers: {
40
- 'x-access-token' => 'jwt'
41
- }
42
- }
43
- args = [:delete, "/ideas/#{idea_id}", options]
44
- expect(project_api).to have_received(:request).with(*args)
37
+ assert_test_case(service, test_result)
45
38
  end
46
39
  end
47
40
  end
@@ -49,17 +49,7 @@ RSpec.describe CmQuiz::Review::GetIdeas do
49
49
  it "should pass test" do
50
50
  test_result = service.perform
51
51
 
52
- expect(test_result).to eq(["get /ideas", true, nil])
53
- options = {
54
- headers: {
55
- 'x-access-token' => 'jwt'
56
- },
57
- query: {
58
- page: 1
59
- }
60
- }
61
- args = [:get, "/ideas", options]
62
- expect(project_api).to have_received(:request).with(*args)
52
+ assert_test_case(service, test_result)
63
53
  end
64
54
  end
65
55
  end
@@ -26,14 +26,7 @@ RSpec.describe CmQuiz::Review::GetUserInfo do
26
26
  it "should pass test" do
27
27
  test_result = service.perform
28
28
 
29
- expect(test_result).to eq(["get /me", true, nil])
30
- options = {
31
- headers: {
32
- 'x-access-token' => 'jwt'
33
- }
34
- }
35
- args = [:get, '/me', options]
36
- expect(project_api).to have_received(:request).with(*args)
29
+ assert_test_case(service, test_result)
37
30
  end
38
31
  end
39
32
  end
@@ -18,7 +18,7 @@ RSpec.describe CmQuiz::Review::LoginUser do
18
18
  it "should pass test" do
19
19
  test_result = service.perform
20
20
 
21
- expect(test_result).to eq(["post /access-tokens", true, nil])
21
+ assert_test_case(service, test_result)
22
22
  end
23
23
  end
24
24
  end
@@ -18,7 +18,7 @@ describe CmQuiz::Review::SignUpUser do
18
18
  it "should pass test" do
19
19
  test_result = service.perform
20
20
 
21
- expect(test_result).to eq(["post /users", true, nil])
21
+ assert_test_case(service, test_result)
22
22
  end
23
23
  end
24
24
  end
@@ -39,20 +39,7 @@ RSpec.describe CmQuiz::Review::UpdateIdea do
39
39
  it "should pass test" do
40
40
  test_result = service.perform
41
41
 
42
- expect(test_result).to eq(["put /ideas/:idea_id", true, nil])
43
- options = {
44
- headers: {
45
- 'x-access-token' => 'jwt'
46
- },
47
- body: {
48
- content: mock_idea[:content],
49
- impact: mock_idea[:impact],
50
- ease: mock_idea[:ease],
51
- confidence: mock_idea[:confidence]
52
- }
53
- }
54
- args = [:put, "/ideas/#{idea_id}", options]
55
- expect(project_api).to have_received(:request).with(*args)
42
+ assert_test_case(service, test_result)
56
43
  end
57
44
  end
58
45
  end
@@ -1,7 +1,13 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('../support', __FILE__)
4
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
3
5
 
4
6
  require 'rubygems'
5
7
  require 'webmock/rspec'
6
8
  require 'cm_quiz'
7
- require 'pry'
9
+ require 'pry'
10
+
11
+ RSpec.configure do |config|
12
+ config.include AssertTestCase
13
+ end
@@ -0,0 +1,12 @@
1
+ module AssertTestCase
2
+ def assert_test_case(service, test_result)
3
+ test_case = {
4
+ verb: service.verb,
5
+ path: service.path,
6
+ options: service.options
7
+ }
8
+ expect(test_result).to eq([test_case, true, nil])
9
+ args = [service.verb, service.path, service.options]
10
+ expect(project_api).to have_received(:request).with(*args)
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm_quiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ben
@@ -108,6 +108,7 @@ files:
108
108
  - spec/lib/cm_quiz/review/sign_up_user_spec.rb
109
109
  - spec/lib/cm_quiz/review/update_idea_spec.rb
110
110
  - spec/spec_helper.rb
111
+ - spec/support/assert_test_case.rb
111
112
  homepage: https://github.com/codementordev/cm_quiz
112
113
  licenses:
113
114
  - MIT