rspec_restful 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb1ea0dce5a1c6cde7c68e6eb1ef0fc34159febe
4
+ data.tar.gz: 08b5c56d6ee71a999aabda62259052954147a610
5
+ SHA512:
6
+ metadata.gz: cc74470693516cbacd7db795ce6e57ecd5a2c8c09f303f1c036d3b521a5d9ea67092f3b5adfac3ba8dce0e0708be99002dcb9f0b4c04aac3af0bec5c5b66dbca
7
+ data.tar.gz: 42c910e87a5a4c16f21dd5765f5b8111d2ba2273ff3fbd3254fe08de8f558b0ee1940d14f02b54cb3fc97ba68abc30e60ac22a277b48c73daf161c5d160bd995
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in restful_test_helpers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jason Langenauer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # RSpec-Restful
2
+
3
+ Simple test helpers that provide easy speccing of basic RESTful controllers that
4
+ only operate on a single ActiveRecord object.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rspec_restful'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install restful_test_helpers
21
+
22
+ ## Usage
23
+
24
+ In `spec/rails_helper.rb` add the following lines:
25
+ ```ruby
26
+ require 'rspec_restful'
27
+
28
+ #...
29
+
30
+ RSpec.configure do |config|
31
+ config.include RspecRestful::ValidityHelpers, type: :controller
32
+ config.extend RspecRestful::ControllerHelpers, type: :controller
33
+ end
34
+ ```
35
+
36
+ In your controller specs, the following macros are now available to test
37
+ the 7 basic REST actions:
38
+
39
+ ```ruby
40
+ RSpec.describe WidgetsController, type: :controller do
41
+ let(:test_widget_params) {{ name: "Goat Herder" }}
42
+
43
+ describe_restful_index_action
44
+ describe_restful_new_action
45
+ describe_restful_create_action(Widget, url_method: :widgets_path)
46
+ describe_restful_edit_action(:widget)
47
+ describe_restful_update_action(Widget, url_method: :widgets_path)
48
+ describe_restful_destroy_action(Widget, url_method: :widgets_path)
49
+ end
50
+ ```
51
+
52
+ This expects that a FactoryGirl factory named `:widget` is available to create
53
+ objects.
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/[my-github-username]/restful_test_helpers/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "restful_test_helpers"
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 ADDED
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,167 @@
1
+ module RspecRestful
2
+ module ControllerHelpers
3
+ def describe_restful_index_action
4
+ describe 'GET :index' do
5
+ before do
6
+ get :index
7
+ end
8
+
9
+ it 'renders the :index template with 200 status' do
10
+ expect(response).to be_success
11
+ expect(response).to render_template('index')
12
+ end
13
+ end
14
+ end
15
+
16
+ def describe_restful_show_action(resource)
17
+ describe 'on GET to :show' do
18
+ let(:item) { create(resource) }
19
+
20
+ before do
21
+ get :show, id: item.id
22
+ end
23
+
24
+ it 'renders the :show template with 200 status' do
25
+ expect(response).to be_success
26
+ expect(response).to render_template('show')
27
+ end
28
+ end
29
+ end
30
+
31
+ def describe_restful_new_action
32
+ describe 'on GET to :new' do
33
+ before do
34
+ get :new
35
+ end
36
+
37
+ it 'renders the :new template with 200 status' do
38
+ expect(response).to be_success
39
+ expect(response).to render_template('new')
40
+ end
41
+ end
42
+ end
43
+
44
+ # Expects a method called test_{class_name}_params to be defined in the
45
+ # current spec group. This should return a hash with the params you want
46
+ # passed to the action.
47
+ def describe_restful_create_action(klass, options = {})
48
+ name = klass.name.underscore
49
+ url_method = options[:url_method] || (name.pluralize + '_url').to_sym
50
+ params_method = ('test_' + name + '_params').to_sym
51
+ name = name.to_sym
52
+
53
+ describe 'POST :create' do
54
+ context 'with valid data' do
55
+ before do
56
+ stub_as_always_valid(klass)
57
+ post :create, name => send(params_method)
58
+ end
59
+
60
+ it "redirects to #{url_method}" do
61
+ expect(response).to be_redirect
62
+ expect(response).to redirect_to(send(url_method))
63
+ end
64
+
65
+ it "creates a #{klass.name}" do
66
+ expect do
67
+ post :create, name => send(params_method)
68
+ end.to change(klass, :count).by(1)
69
+ end
70
+ end
71
+
72
+ context 'with invalid data' do
73
+ before do
74
+ stub_as_never_valid(klass)
75
+ post :create, name => send(params_method)
76
+ end
77
+
78
+ it 'renders the :new template with 200 status' do
79
+ expect(response).to be_success
80
+ expect(response).to render_template(:new)
81
+ end
82
+
83
+ it "doesn't create a #{klass.name}" do
84
+ expect do
85
+ post :create, name => send(params_method)
86
+ end.not_to change(klass, :count)
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ def describe_restful_edit_action(resource)
93
+ describe 'GET :edit' do
94
+ let(:item) { create(resource) }
95
+
96
+ before do
97
+ get :edit, id: item.id
98
+ end
99
+
100
+ it 'renders the :edit template with 200 status' do
101
+ expect(response).to be_success
102
+ expect(response).to render_template('edit')
103
+ end
104
+ end
105
+ end
106
+
107
+ def describe_restful_update_action(klass, options = {})
108
+ name = klass.name.underscore
109
+ url_method = options[:url_method] || (name.pluralize + '_url').to_sym
110
+ params_method = ('test_' + name + '_params').to_sym
111
+ name = name.to_sym
112
+
113
+ describe 'on PUT to :update' do
114
+ before { @item = create(name) }
115
+
116
+ context 'with valid data' do
117
+ before do
118
+ stub_as_always_valid(klass)
119
+ put :update, id: @item.id, name => send(params_method)
120
+ end
121
+
122
+ it "redirects to #{url_method}" do
123
+ expect(response).to be_redirect
124
+ expect(response).to redirect_to(send(url_method))
125
+ end
126
+ end
127
+
128
+ context 'with invalid data' do
129
+ before do
130
+ stub_as_never_valid(klass)
131
+ put :update, id: @item.id, name => send(params_method)
132
+ end
133
+
134
+ it 'renders the :edit template with 200 status' do
135
+ expect(response).to be_success
136
+ expect(response).to render_template('edit')
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ def describe_restful_destroy_action(klass, options = {})
143
+ name = klass.name.underscore
144
+ url_method = options[:url_method] || (name.pluralize + '_url').to_sym
145
+ name = name.to_sym
146
+
147
+ describe 'on DELETE to :destroy' do
148
+ before do
149
+ @item = create(name)
150
+ delete :destroy, id: @item.id
151
+ end
152
+
153
+ it "redirects to #{url_method}" do
154
+ expect(response).to be_redirect
155
+ expect(response).to redirect_to(send(url_method))
156
+ end
157
+
158
+ it "destroys a #{klass.name}" do
159
+ @item = create(name)
160
+ expect do
161
+ delete :destroy, id: @item.id
162
+ end.to change(klass, :count).by(-1)
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,11 @@
1
+ module RspecRestful
2
+ module ValidityHelpers
3
+ def stub_as_always_valid(klass)
4
+ allow_any_instance_of(klass).to receive(:valid?).and_return(true)
5
+ end
6
+
7
+ def stub_as_never_valid(klass)
8
+ allow_any_instance_of(klass).to receive(:valid?).and_return(false)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RspecRestful
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "rspec_restful/version"
2
+ require "rspec_restful/validity_helpers"
3
+ require "rspec_restful/controller_helpers"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_restful/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec_restful"
8
+ spec.version = RspecRestful::VERSION
9
+ spec.authors = ["Jason Langenauer"]
10
+ spec.email = ["jasonl@jobready.com.au"]
11
+
12
+ spec.summary = %q{RSpec helpers to easily test RESTful controllers}
13
+ spec.description = %q{RSpec helpers to easily test RESTful controllers}
14
+ spec.homepage = "https://github.com/jobready/rspec-restful"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_restful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Langenauer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: RSpec helpers to easily test RESTful controllers
42
+ email:
43
+ - jasonl@jobready.com.au
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/rspec_restful.rb
58
+ - lib/rspec_restful/controller_helpers.rb
59
+ - lib/rspec_restful/validity_helpers.rb
60
+ - lib/rspec_restful/version.rb
61
+ - rspec_restful.gemspec
62
+ homepage: https://github.com/jobready/rspec-restful
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: RSpec helpers to easily test RESTful controllers
86
+ test_files: []
87
+ has_rdoc: