rspec-grape 0.0.1 → 0.0.2

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: ce1c2bd204c85ed12e3882ec9dae4fef40b3564a
4
- data.tar.gz: 6bfef25db90716def3574f63c8f5037512e76610
3
+ metadata.gz: 61834a03e2598768f0724919732a86f1204c997c
4
+ data.tar.gz: 39a042a5038ec2596505223a3df4017587f7c84a
5
5
  SHA512:
6
- metadata.gz: b972ea8f1a983a193b72eb42cc78c320aff74c256cb55d55eafe1c585b9cc936e55e57ebf742ad5a9123d9fb23ad41b055c9f7cd9cec127d2e6285565cd0efde
7
- data.tar.gz: 99b912315880faca5b9fdf3585d3911539c415a1d7b098e57cb393c2ed9dd15f3caeb4da1108647f3e97fac3dd6351726b5f2eec2dfcfe9bdb93c537949d82d5
6
+ metadata.gz: 5d1d279c4611105cc38a690606036df67fd8667df68210a1bb508dcfb82e943c27ada97feaf11576549380f7d6341c05d928be8e5ffcccfc40ee9b573ebe2f03
7
+ data.tar.gz: 7bf5c4314dc0e3ff8e1ea7f06c1962aa5cf5f951d492963fa53e01044a27a98f06cd1c2ec4173fb2f12c19bba76d2951afd62659ca258b130a2b27b822216eaf
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This gem is a set of spec helpers, that will help to test [Grape](https://github.com/ruby-grape/grape) APIs easily. The usual approach to test apis, as [official documentation shows](https://github.com/ruby-grape/grape#rspec), is:
4
4
 
5
- ```
5
+ ```ruby
6
6
  context 'GET /api/v1/test' do
7
7
  it 'returns 200' do
8
8
  get '/api/v1/test'
@@ -39,11 +39,20 @@ Gem's behaviour is based on some conventions:
39
39
  * examples should be grouped by endpoints
40
40
  * group of endpoint specs shoud be described as 'HTTP_METHOD /api/path'
41
41
 
42
+ In order to have helpers available in examples, you need to add `type: :api` metadata:
43
+ ```ruby
44
+ describe MyAPI, type: :api do
45
+ ```
46
+ Or use a symbol:
47
+ ```ruby
48
+ describe MyAPI, :api do
49
+ ```
50
+
42
51
  ### Basic usage
43
52
 
44
53
  This gem provides the `call_api` helper method. It automatically reads endpoint url and method from context description, allowing you to avoid duplication and write a shorter spec:
45
54
 
46
- ```
55
+ ```ruby
47
56
  context 'GET /api/v1/test' do
48
57
  it 'returns 200' do
49
58
  expect(call_api.status).to eq(200)
@@ -55,18 +64,28 @@ end
55
64
 
56
65
  Params can be either passed to `call_api` method:
57
66
 
58
- ```
67
+ ```ruby
59
68
  call_api({foo: :bar})
60
69
  ```
61
70
 
62
71
  or set via `let`:
63
72
 
64
- ```
73
+ ```ruby
65
74
  let(:api_params) { { foo: :bar } }
66
75
  ```
67
76
 
68
77
  Note, that params, explicitly passed to `call_api`, have precendence over thoose set in `api_params`.
69
78
 
79
+ ### Stubbing API helpers
80
+
81
+ rspec-grape provides two methods to stub API helpers: `expect_endpoint_to` and `expect_endpoint_not_to`. You can easily write:
82
+
83
+ ```ruby
84
+ expect_endpoint_to receive(:help_me)
85
+ expect_endpoint_not_to receive(:dont_help)
86
+ ```
87
+
88
+ Note that under the hood those methods use `Grape::Endpoint.before_each`, as suggested by [documentation](https://github.com/ruby-grape/grape#stubbing-helpers). Thanks to [Jon Rowe](https://github.com/JonRowe) for the idea.
70
89
 
71
90
  ### Additional spec helpers
72
91
 
@@ -74,14 +93,15 @@ It is also possible to use two methods in your specs: `api_url` and `api_method`
74
93
 
75
94
  You can always use them, as `call_api` methods does:
76
95
 
77
- ```
96
+ ```ruby
78
97
  send(api_method, api_url)
79
98
  ```
80
99
 
100
+ Note that you do not need to `include Rack::Test::Methods` as they are already included by gem.
101
+
81
102
  ## TODO
82
103
 
83
104
  * Support urls with params: `/api/test/:id`
84
- * Provide `api_helpers` for easier helpers stubbing [see](https://github.com/ruby-grape/grape#stubbing-helpers)
85
105
 
86
106
  ## Development
87
107
 
@@ -8,4 +8,11 @@ require 'rspec/grape/methods'
8
8
  RSpec.configure do |config|
9
9
  config.include RSpec::Grape::Methods, type: :api
10
10
  config.include RSpec::Grape::Methods, :api
11
+
12
+ after = Proc.new do
13
+ ::Grape::Endpoint.before_each nil
14
+ end
15
+
16
+ config.after(:each, :api, &after)
17
+ config.after(:each, type: :api, &after)
11
18
  end
@@ -21,6 +21,15 @@ module RSpec
21
21
  self.send(api_method, api_url, params)
22
22
  end
23
23
 
24
+ def expect_endpoint_to(matcher)
25
+ ::Grape::Endpoint.before_each { |endpoint| expect(endpoint).to matcher }
26
+ end
27
+
28
+ def expect_endpoint_not_to(matcher)
29
+ ::Grape::Endpoint.before_each { |endpoint| expect(endpoint).not_to matcher }
30
+ end
31
+
32
+
24
33
  private
25
34
 
26
35
  def api_endpoint_description
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Grape
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -14,8 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
17
  spec.require_paths = ["lib"]
20
18
 
21
19
  spec.add_runtime_dependency "rack-test", "~> 0.6"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timothy Kovalev
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-15 00:00:00.000000000 Z
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-test
@@ -108,8 +108,6 @@ files:
108
108
  - LICENSE.txt
109
109
  - README.md
110
110
  - Rakefile
111
- - bin/console
112
- - bin/setup
113
111
  - lib/rspec-grape.rb
114
112
  - lib/rspec/grape/exceptions.rb
115
113
  - lib/rspec/grape/methods.rb
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rspec/grape"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here