rspec_request_helpers 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 6123bd35683c01320a81b8b564d8dd518298489c2063be3ea2b83460cde16153
4
- data.tar.gz: 595d6b0cede37d70e8e0a6fabc2efae031c1cb33d2a737ed7bc49391a76ab5c3
3
+ metadata.gz: 91adebd9c1dabd6ddca1e5cfcbdb89e99fb2206cda1ca33ab3d668394a196e45
4
+ data.tar.gz: f66ddb343374709b07238a35307d678b8db57c085ca7692e35ea5534c5230418
5
5
  SHA512:
6
- metadata.gz: 552e36a4241ab85cc6933ced18d29b315fee8e7436a5b98f1cedc071981d5c94e0b46400f0a05bc9a7642a3c3c6346c69cd48482c0f161002d26dd8886005238
7
- data.tar.gz: 0329fc125a3c35e2477b5d91e8908658c77c36c9fef6dd382b94964c46e151c21344981309b6ef80be9c9f9c61aff20414382197ec072434a790de21cd4fafca
6
+ metadata.gz: a345f449c50de4de835926f81aa00b595a57c36f585b8673f4ad2c5f6cfa52824fc725f7c378c0b11d0925b0474b426c09e27242b2a1b4eb98c6b47d05a14aa8
7
+ data.tar.gz: 6be451b2491f92893dd08d8a94df520a84f6272602d719991cb54f099e91793bb3d92f60c263b582dbd6564dea197d6ad71213ae2bac0d4db3bdc0abcc742592
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec_request_helpers (0.2.0)
4
+ rspec_request_helpers (0.2.1)
5
5
  actionpack (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
  factory_bot
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Rspec Request Helpers
2
2
 
3
3
  This gem provides few tools to make testing of API endpoint in your Rails application more effective.
4
+
5
+ [![RSpec flow part 1](http://img.youtube.com/vi/YkZYNlUHHOg/1.jpg)](http://www.youtube.com/watch?v=YkZYNlUHHOg) [![RSpec flow part 2](http://img.youtube.com/vi/CB60JdImYC4/2.jpg)](http://www.youtube.com/watch?v=CB60JdImYC4)
6
+
4
7
  This rules were influenced by real projects experience so
5
8
  In order to use it in your `rspec/requests` specs you need to follow one rule:
6
9
 
7
- For every test example you need to define `path`, `valid_headers`, `valid_params`, and `expected_response`.
10
+ For every test example you need to define path, headers, params, and expected_response.
8
11
 
9
12
  NOTE: version 0.1.1 introduced the helpers which ensure naming conventions. They have identical names and in fact are
10
13
  wrappers around RSpec `let` functionality.
@@ -36,6 +39,18 @@ database do
36
39
  end
37
40
  ```
38
41
 
42
+ Since version 0.2.1 there is an ability to define regular variables which text example depends on in separate block with handy syntax support
43
+
44
+ ```ruby
45
+ vars do
46
+ variant_id { variant.id }
47
+ issue_id { issue.id }
48
+ issue_message { 'Packed 5 instead of 3 items' }
49
+ item_id { item.id }
50
+ mispick_report { MispickReport.last }
51
+ end
52
+ ```
53
+
39
54
  ## Installation
40
55
 
41
56
  Add this line to your application's Gemfile:
@@ -56,7 +71,7 @@ In project directory run
56
71
 
57
72
  $ rails g rspec_request_helpers:install
58
73
 
59
- ## Usage
74
+ ## Configuration
60
75
 
61
76
  Include helpers into RSpec
62
77
 
@@ -73,8 +88,6 @@ RSpec.configure do |config|
73
88
  end
74
89
  ```
75
90
 
76
- ## Configuration
77
-
78
91
  Create file `config/initializers/rspec_request_helpers.rb`
79
92
 
80
93
  ```ruby
@@ -86,8 +99,13 @@ RspecRequestHelpers.configure do |config|
86
99
  config.status_codes = [404, 401, 422, 200, 201]
87
100
  end
88
101
  ```
102
+ ## Usage
103
+
104
+ ### Generate new rspec file for API endpoint
105
+
106
+ $ rails g rspec:endpoint <action name> <namespaced controller>
89
107
 
90
- Generate new file for API endpoint
108
+ Example:
91
109
 
92
110
  $ rails g rspec:endpoint show api/v1/users
93
111
 
@@ -40,16 +40,35 @@ module RspecRequestHelpers
40
40
  self.class_eval(rspec_factory)
41
41
  end
42
42
 
43
+ class VarsDSL
44
+ def initialize(klass)
45
+ @klass = klass
46
+ end
47
+
48
+ def method_missing(method_name, *args, &block)
49
+ case method_name
50
+ when /!$/
51
+ @klass.class_eval { let!(:"#{method_name.to_s.sub(/!$/,'')}", &block) }
52
+ else
53
+ @klass.class_eval { let(method_name, &block) }
54
+ end
55
+ end
56
+ end
57
+
58
+ def vars(&block)
59
+ VarsDSL.new(self).instance_eval(&block)
60
+ end
61
+
43
62
  def path(&block)
44
63
  let(:path, &block)
45
64
  end
46
65
 
47
- def valid_params(&block)
48
- let(:valid_params, &block)
66
+ def params(&block)
67
+ let(:params, &block)
49
68
  end
50
69
 
51
- def valid_headers(&block)
52
- let(:valid_headers, &block)
70
+ def headers(&block)
71
+ let(:headers, &block)
53
72
  end
54
73
 
55
74
  def expected_response(&block)
@@ -97,9 +116,9 @@ module RspecRequestHelpers
97
116
  %i(get post put patch delete).each do |http_verb|
98
117
  define_method :"do_#{http_verb}" do
99
118
  if Rails::VERSION::MAJOR >= 5
100
- public_send(http_verb, path, params: valid_params, headers: valid_headers)
119
+ public_send(http_verb, path, params: params, headers: headers)
101
120
  else
102
- public_send(http_verb, path, valid_params, valid_headers)
121
+ public_send(http_verb, path, params, headers)
103
122
  end
104
123
  end
105
124
 
@@ -1,3 +1,3 @@
1
1
  module RspecRequestHelpers
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_request_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Baran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport