rspec-api 0.1.0 → 0.1.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: 5408552b4ac63e6bdbbd372c3c900c963f14ffbe
4
- data.tar.gz: 53fa90f938352139f11677ae6b414fc32535ea47
3
+ metadata.gz: a73666993aeb89c6f6d8256fbd334cf95042c055
4
+ data.tar.gz: b2c4a007b05a4a00427b169dc1bde8440852243b
5
5
  SHA512:
6
- metadata.gz: 8b86970f33d662320ac5189e82aa1117f1cf44d0ffe583a30c0cae3d4440181769e96cff3cfa7766fd75126d5227423931ffcbc0e3e9801bf123d776bbf53c58
7
- data.tar.gz: dddc04c7ced68aa44e82856ce4b73187af7671cc7b6be7b33f1a72ff84f264895356e85542d6eaa3cf6a9974c18b62c2d30c72f8545ef4585b6a4ddd87860429
6
+ metadata.gz: 172cff78f4cf2cc300fa1e049975cb80604cccc8aa967156d9363b81cee93ee1321e82d1b68f720678f8ec3abd75c48ae95a87aac93d40049ca20675ae46bd7a
7
+ data.tar.gz: f380e9efcb009d145b5faa83792be55a4e0a6c527026498318fc99702189af5c94612b32099bcd1546a471b6e39a9632206004a4c472f257fccdeb06f6508d6a
data/README.md CHANGED
@@ -1,2 +1,3 @@
1
1
  # RSpec API
2
2
 
3
+ More info at [http://rspec-api.github.io](http://rspec-api.github.io)
@@ -40,8 +40,8 @@ module DSL
40
40
 
41
41
  def should_be_filtered_by(filter_options)
42
42
  it {
43
- if json_value = request_params[filter_options[:parameter].to_s]
44
- expect(response_body).to be_filtered_by(filter_options[:attribute], json_value)
43
+ if json_value = request_params[filter_options[:name].to_s]
44
+ expect(response_body).to be_filtered_by(json_value, filter_options)
45
45
  else
46
46
  expect(response_body).to be_filtered_by(nil)
47
47
  end
@@ -13,6 +13,7 @@ module DSL
13
13
 
14
14
  define_action :get
15
15
  define_action :put
16
+ define_action :patch
16
17
  define_action :post
17
18
  define_action :delete
18
19
 
@@ -32,7 +33,7 @@ module DSL
32
33
 
33
34
  # TODO: the second 'accepts_filter' should not override the first, but add
34
35
  def accepts_filter(filter_parameter, options={})
35
- rspec_api[:filter] = {parameter: filter_parameter, attribute: options[:on]}
36
+ rspec_api[:filter] = options.merge(name: filter_parameter)
36
37
  end
37
38
 
38
39
  private
@@ -42,15 +42,15 @@ module DSL
42
42
  [].tap do |optional_params|
43
43
  optional_params << {} # default: no extra params
44
44
  if rspec_api[:array]
45
- if rspec_api[:sort]
46
- optional_params << {sort: rspec_api[:sort][:parameter]}
47
- optional_params << {sort: "-#{rspec_api[:sort][:parameter]}"}
45
+ if sort = rspec_api[:sort]
46
+ optional_params << {sort: sort[:parameter]}
47
+ optional_params << {sort: "-#{sort[:parameter]}"}
48
48
  end
49
49
  if rspec_api[:page]
50
50
  optional_params << {page: 2}
51
51
  end
52
- if rspec_api[:filter]
53
- optional_params << {rspec_api[:filter][:parameter] => existing(rspec_api[:filter][:attribute])}
52
+ if filter = rspec_api[:filter]
53
+ optional_params << {filter[:name] => existing(filter[:on])}
54
54
  end
55
55
  end
56
56
  end
data/lib/rspec-api/dsl.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rspec-api/dsl/resource'
2
- require 'rspec-api/dsl/get'
2
+ require 'rspec-api/dsl/route'
3
3
  require 'rspec-api/dsl/request'
4
4
 
5
5
  module DSL
@@ -0,0 +1,15 @@
1
+ module Http
2
+ module Local
3
+ module Request
4
+ extend ActiveSupport::Concern
5
+
6
+ def response
7
+ last_response
8
+ end
9
+
10
+ def request_params
11
+ last_request.params
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Http
2
+ module Local
3
+ module Route
4
+ extend ActiveSupport::Concern
5
+
6
+ def send_request(verb, route, body)
7
+ header 'Accept', 'application/json'
8
+ send verb, route, body
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'rack/test'
2
+ require 'rspec-api/http/local/route'
3
+ require 'rspec-api/http/local/request'
4
+
5
+ def app
6
+ Rails.application
7
+ end
8
+
9
+ RSpec.configuration.include Rack::Test::Methods, rspec_api_dsl: :route
10
+ RSpec.configuration.include Http::Local::Route, rspec_api_dsl: :route
11
+ RSpec.configuration.include Http::Local::Request, rspec_api_dsl: :request
@@ -1,40 +1,11 @@
1
1
  require 'rack/test'
2
+ require 'rspec-api/http/local/route'
3
+ require 'rspec-api/http/local/request'
2
4
 
3
5
  def app
4
6
  Rails.application
5
7
  end
6
8
 
7
- module DSL
8
- module RackTest
9
- module Route
10
- extend ActiveSupport::Concern
11
-
12
- def send_request(verb, route, body)
13
- header 'Accept', 'application/json'
14
- send verb, route, body
15
- end
16
- end
17
- end
18
- end
19
-
20
-
21
- module DSL
22
- module RackTest
23
- module Request
24
- extend ActiveSupport::Concern
25
-
26
- def response
27
- last_response
28
- end
29
-
30
- def request_params
31
- last_request.params
32
- end
33
- end
34
- end
35
- end
36
-
37
-
38
9
  RSpec.configuration.include Rack::Test::Methods, rspec_api_dsl: :route
39
- RSpec.configuration.include DSL::RackTest::Route, rspec_api_dsl: :route
40
- RSpec.configuration.include DSL::RackTest::Request, rspec_api_dsl: :request
10
+ RSpec.configuration.include Http::Local::Route, rspec_api_dsl: :route
11
+ RSpec.configuration.include Http::Local::Request, rspec_api_dsl: :request
@@ -0,0 +1,15 @@
1
+ module Http
2
+ module Remote
3
+ module Request
4
+ extend ActiveSupport::Concern
5
+
6
+ def response
7
+ @last_response
8
+ end
9
+
10
+ def request_params
11
+ @last_request.params
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Http
2
+ module Remote
3
+ module Resource
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def authorize_with(options = {})
8
+ rspec_api[:authorization] = options
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Http
2
+ module Remote
3
+ module Route
4
+ extend ActiveSupport::Concern
5
+
6
+ def send_request(verb, route, body)
7
+ logger = Logger.new 'log/faraday.log'
8
+
9
+ conn = Faraday.new 'https://api.github.com/' do |c| # TODO: Pass host as a parameter
10
+ # NOTE: The order is **important**! Leave HttpCache first
11
+ c.use Faraday::HttpCache, store: :file_store, store_options: ['/tmp/faraday'], logger: logger
12
+ c.use FaradayMiddleware::EncodeJson # query params are not JSON(body) but data are
13
+ c.use Faraday::Response::Logger, logger
14
+ c.use Faraday::Adapter::NetHttp
15
+ end
16
+
17
+ conn.headers[:user_agent] = 'RSpec API'
18
+ conn.authorization *authorization.flatten
19
+ sleep 0.5 # TODO: Pass as a parameter
20
+
21
+ @last_response = conn.send verb, route, body do |request|
22
+ @last_request = request
23
+ end
24
+ end
25
+
26
+ def authorization
27
+ # TODO: Any other way to access metadata in a before(:all) ?
28
+ self.class.metadata[:rspec_api][:authorization]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware' # TODO: use autoload, we only need EncodeJson
3
+ require 'faraday-http-cache'
4
+
5
+ # faraday-http-cache is a great gem that correctly ignores Private Cache
6
+ # For the sake of saving Github calls, let's cache Private as well!
7
+ module Faraday
8
+ class HttpCache
9
+ class CacheControl
10
+ def private?
11
+ false
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ require 'rspec-api/http/remote/resource'
18
+ require 'rspec-api/http/remote/route'
19
+ require 'rspec-api/http/remote/request'
20
+
21
+ RSpec.configuration.include Http::Remote::Resource, rspec_api_dsl: :resource
22
+ RSpec.configuration.include Http::Remote::Request, rspec_api_dsl: :request
23
+ RSpec.configuration.include Http::Remote::Route, rspec_api_dsl: :route
@@ -1,9 +1,15 @@
1
- RSpec::Matchers.define :be_filtered_by do |filtered_attribute, json_value=nil|
1
+ RSpec::Matchers.define :be_filtered_by do |json_value, options = {}|
2
+ filtered_attribute = options[:on]
3
+ compare = options[:comparing_with] || Proc.new{|x,y| x == y}
4
+
2
5
  match do |items|
3
6
  if filtered_attribute.nil?
4
7
  true
5
8
  else
6
- items.all?{|item| item[filtered_attribute.to_s].to_s == json_value}
9
+ items.all? do |item|
10
+ # TODO: Don't always use string
11
+ compare.call json_value, item[filtered_attribute.to_s].to_s
12
+ end
7
13
  end
8
14
  end
9
15
 
@@ -11,6 +17,7 @@ RSpec::Matchers.define :be_filtered_by do |filtered_attribute, json_value=nil|
11
17
  if filtered_attribute.nil?
12
18
  %Q(not be filtered by any specific attribute)
13
19
  else
20
+ # TODO: Change description based on operator
14
21
  %Q(be filtered by #{filtered_attribute.to_json} => #{json_value})
15
22
  end
16
23
  end
@@ -1,3 +1,3 @@
1
1
  module RspecApi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-http-cache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.0
27
55
  description: Helpers to write specs for web APIs
28
56
  email:
29
57
  - claudiob@gmail.com
@@ -31,15 +59,21 @@ executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
34
- - lib/rspec-api/active_resource.rb
35
- - lib/rspec-api/dsl/get.rb
36
62
  - lib/rspec-api/dsl/request/body.rb
37
63
  - lib/rspec-api/dsl/request/headers.rb
38
64
  - lib/rspec-api/dsl/request/status.rb
39
65
  - lib/rspec-api/dsl/request.rb
40
66
  - lib/rspec-api/dsl/resource.rb
67
+ - lib/rspec-api/dsl/route.rb
41
68
  - lib/rspec-api/dsl.rb
69
+ - lib/rspec-api/http/local/request.rb
70
+ - lib/rspec-api/http/local/route.rb
71
+ - lib/rspec-api/http/local.rb
42
72
  - lib/rspec-api/http/rack_test.rb
73
+ - lib/rspec-api/http/remote/request.rb
74
+ - lib/rspec-api/http/remote/resource.rb
75
+ - lib/rspec-api/http/remote/route.rb
76
+ - lib/rspec-api/http/remote.rb
43
77
  - lib/rspec-api/matchers/attributes.rb
44
78
  - lib/rspec-api/matchers/body.rb
45
79
  - lib/rspec-api/matchers/content_type.rb
@@ -1,85 +0,0 @@
1
- require 'faraday'
2
-
3
- module DSL
4
- module ActiveResource
5
- module Route
6
- extend ActiveSupport::Concern
7
-
8
- def send_request(verb, route, body)
9
- conn = Faraday.new 'https://api.github.com/' do |c|
10
- c.use Faraday::Response::Logger, Logger.new('log/faraday.log')
11
- c.use Faraday::Adapter::NetHttp
12
- end
13
-
14
- conn.headers[:user_agent] = 'RSpec API for Github'
15
- conn.authorization *authorization.flatten
16
-
17
- @last_response = conn.send verb, route, (body.to_json if body.present?)
18
- end
19
-
20
- def authorization
21
- # TODO: Any other way to access metadata in a before(:all) ?
22
- self.class.metadata[:rspec_api][:authorization]
23
- end
24
-
25
- module ClassMethods
26
-
27
- def setup_fixtures
28
- # nothing to do for now...
29
- end
30
-
31
- def existing(field)
32
- case field
33
- when :user then 'claudiob'
34
- when :gist_id then '0d7b597d822102148810'
35
- when :id then '921225'
36
- end
37
- end
38
-
39
- def unknown(field)
40
- case field
41
- when :user then 'not-a-valid-user'
42
- when :gist_id then 'not-a-valid-gist-id'
43
- when :id then 'not-a-valid-id'
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
-
51
-
52
- module DSL
53
- module ActiveResource
54
- module Resource
55
- extend ActiveSupport::Concern
56
-
57
- module ClassMethods
58
- def authorize_with(options = {})
59
- rspec_api[:authorization] = options
60
- end
61
- end
62
- end
63
- end
64
- end
65
-
66
-
67
- module DSL
68
- module ActiveResource
69
- module Request
70
- extend ActiveSupport::Concern
71
-
72
- def response
73
- @last_response
74
- end
75
-
76
- def request_params
77
- # TO DO
78
- end
79
- end
80
- end
81
- end
82
-
83
- RSpec.configuration.include DSL::ActiveResource::Resource, rspec_api_dsl: :resource
84
- RSpec.configuration.include DSL::ActiveResource::Request, rspec_api_dsl: :request
85
- RSpec.configuration.include DSL::ActiveResource::Route, rspec_api_dsl: :route