webmock-symbol-http-status 0.1.0 → 0.2.0

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: 020a5b6d082945d1f0e1d425265f43304b91edfb
4
- data.tar.gz: 18383a90cccde01efe061a222156a85309e4dfae
3
+ metadata.gz: 6b0dd100f0f4d025357cfbc74ec7afa870690797
4
+ data.tar.gz: 2dce4bb2a69318f1b349572ee93161df49e48040
5
5
  SHA512:
6
- metadata.gz: 0e18914bedb49f0721d34e7fd43a3bb636981e42781fb06744614564cd49b67136242b6a07f5a8ab81879388cb2cf9ed5c99ee623452f05df70167f43dbd29de
7
- data.tar.gz: 054337ca8bed3a3a4c30d0cad2aff1a07f3de2e1f2fc90b4369aa1561d7683a61c762c6f624aef3af89daa7a1b8b23814e815efbfba0db96aac04c45882a594c
6
+ metadata.gz: ec7068d1ad8d0f74e5dc84cc50795a8649e3e9c7c629cce6b66743e80b5eb83f2d3d8828b607c510be173cb09ae362629719533647dea46f523609cb315293fd
7
+ data.tar.gz: 7a8e52e2eae037bb5c8549dd1f050a0e9ddd25ed9386d231ca168dc08d1ecc9460247abca6d648c7a73f7693b5d1a6a985c0f26d025a3e77d1c6f05f9943f827
@@ -1,12 +1,28 @@
1
1
  version: 2
2
2
  jobs:
3
- build:
3
+ test_2_3:
4
4
  docker:
5
- - image: circleci/ruby:2.4.2
5
+ - image: circleci/ruby:2.3.5
6
6
  steps:
7
7
  - checkout
8
+ - run: bundle install
9
+ - run: bundle exec rake spec
8
10
 
11
+ test_2_4:
12
+ docker:
13
+ - image: circleci/ruby:2.4.2
14
+ steps:
15
+ - checkout
9
16
  - run: bundle install
17
+ - run: bundle exec rake spec
18
+
19
+ workflows:
20
+ version: 2
21
+ test_multi_ruby_version:
22
+ jobs:
23
+ - test_2_3
24
+ - test_2_4
10
25
 
11
- - type: shell
12
- command: bundle exec rake spec
26
+ notify:
27
+ webhooks:
28
+ - url: https://idobata.io/hook/circle_ci/52bbf489-8c7a-44f0-a702-59b5a1243c0f
data/README.md CHANGED
@@ -19,6 +19,9 @@ gem 'webmock-symbol-http-status'
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
+ require 'webmock/rspec'
23
+ require 'webmock_symbol_http_status'
24
+
22
25
  stub_request(:get, 'www.example.com').
23
26
  to_return(status: :ok)
24
27
  ```
@@ -0,0 +1,37 @@
1
+ require 'webmock/util/hash_keys_stringifier'
2
+ require 'webmock/util/hash_validator'
3
+ require 'webmock/util/headers'
4
+
5
+ require 'rack'
6
+
7
+ module SymbolHttpStatusAble
8
+ def options=(options)
9
+ options = WebMock::Util::HashKeysStringifier.stringify_keys!(options)
10
+ WebMock::HashValidator.new(options).validate_keys('headers', 'status', 'body', 'exception', 'should_timeout')
11
+ self.headers = options['headers']
12
+ self.status = convert_numeric_status(options['status'])
13
+ self.body = options['body']
14
+ self.exception = options['exception']
15
+ @should_timeout = options['should_timeout']
16
+ end
17
+
18
+ private
19
+
20
+ def convert_numeric_status(response)
21
+ if response.is_a?(Array)
22
+ [numeric_status(response[0]), response[1]]
23
+ elsif response.is_a?(Proc)
24
+ response
25
+ else
26
+ numeric_status(response)
27
+ end
28
+ end
29
+
30
+ def numeric_status(status)
31
+ if status.is_a?(Integer)
32
+ status
33
+ else
34
+ Rack::Utils::SYMBOL_TO_STATUS_CODE[status]
35
+ end
36
+ end
37
+ end
@@ -1,22 +1,9 @@
1
- require 'webmock/util/hash_keys_stringifier'
2
- require 'webmock/util/hash_validator'
3
- require 'webmock/util/headers'
4
-
5
1
  require 'webmock/response'
6
2
 
7
- require 'numeric_status'
3
+ require 'symbol_http_status_able'
8
4
 
9
- # Open class
10
5
  module WebMock
11
6
  class Response
12
- def options=(options)
13
- options = WebMock::Util::HashKeysStringifier.stringify_keys!(options)
14
- HashValidator.new(options).validate_keys('headers', 'status', 'body', 'exception', 'should_timeout')
15
- self.headers = options['headers']
16
- self.status = NumericStatus.new(options['status']).response
17
- self.body = options['body']
18
- self.exception = options['exception']
19
- @should_timeout = options['should_timeout']
20
- end
7
+ prepend SymbolHttpStatusAble
21
8
  end
22
9
  end
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'webmock-symbol-http-status'
6
- spec.version = '0.1.0'
6
+ spec.version = '0.2.0'
7
7
  spec.authors = ['taki3']
8
8
  spec.email = ['taki3@users.noreply.github.com']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock-symbol-http-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - taki3
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-07 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -109,7 +109,7 @@ files:
109
109
  - LICENSE.txt
110
110
  - README.md
111
111
  - Rakefile
112
- - lib/numeric_status.rb
112
+ - lib/symbol_http_status_able.rb
113
113
  - lib/webmock_symbol_http_status.rb
114
114
  - webmock-symbol-http-status.gemspec
115
115
  homepage: https://github.com/ayindi/webmock-symbol-http-status
@@ -1,34 +0,0 @@
1
- require 'rack'
2
-
3
- class NumericStatus
4
- def initialize(response)
5
- if response.is_a?(Array)
6
- @status = numeric_status(response[0])
7
- @body = response[1]
8
- elsif response.is_a?(Proc)
9
- @proc = response
10
- else
11
- @status = numeric_status(response)
12
- end
13
- end
14
-
15
- def response
16
- if instance_variable_defined?(:@body)
17
- [@status, @body]
18
- elsif instance_variable_defined?(:@proc)
19
- @proc
20
- else
21
- @status
22
- end
23
- end
24
-
25
- private
26
-
27
- def numeric_status(status)
28
- if status.is_a?(Integer)
29
- status
30
- else
31
- Rack::Utils::SYMBOL_TO_STATUS_CODE[status]
32
- end
33
- end
34
- end