rack-minitest 0.0.6

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/ruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-minitest.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Brandon Weiss
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # rack-minitest
2
+
3
+ `rack-minitest` = `rack-test` + `MiniTest`. See what I did there?
4
+
5
+ This gem adds some convenience methods to `rack-test` and `MiniTest` that I found myself duplicating over and over for every application I wrote. It adds a few methods for dealing with JSON to `rack-test` and `MiniTest` spec-style matchers for checking response status. The specific methods are:
6
+
7
+ ```
8
+ last_json_response
9
+
10
+ get_json path, params
11
+ post_json path, params
12
+ put_json path, params
13
+ delete_json path, params
14
+
15
+ last_response.must_be_ok
16
+ last_response.must_be_created
17
+ last_response.must_be_unauthorized
18
+ last_response.must_be_not_found
19
+ last_response.must_be_unprocessable_entity
20
+ ```
21
+
22
+ **NB**: This is a quick and dirty gem to hack in some functionality that I was surprised to find didn't already exist. There are tests, and they pass, but they're pretty gross. All improvements are welcome.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem "rack-minitest", git: "git://github.com/brandonweiss/rack-minitest.git"
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ ## Usage
35
+
36
+ Just add the appropriate requires _after_ you load `rack-test` and `MiniTest`.
37
+
38
+ ```
39
+ require "rack-minitest/assertions"
40
+ require "rack-minitest/spec"
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ task :environment do
6
+ require "./app/environment"
7
+ end
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.pattern = "test/**/*_test.rb"
11
+ t.verbose = false
12
+ end
13
+
14
+ task :default => :test
@@ -0,0 +1 @@
1
+ require "rack-minitest/version"
@@ -0,0 +1,48 @@
1
+ module MiniTest::Assertions
2
+
3
+ def assert_ok(response)
4
+ assert_response_status response, 200
5
+ end
6
+
7
+ def assert_created(response)
8
+ assert_response_status response, 201
9
+ end
10
+
11
+ def assert_moved_permanently(response)
12
+ assert_response_status response, 301
13
+ end
14
+
15
+ def assert_bad_request(response)
16
+ assert_response_status response, 400
17
+ end
18
+
19
+ def assert_unauthorized(response)
20
+ assert_response_status response, 401
21
+ end
22
+
23
+ def assert_not_found(response)
24
+ assert_response_status response, 404
25
+ end
26
+
27
+ def assert_unprocessable_entity(response)
28
+ assert_response_status response, 422
29
+ end
30
+
31
+ def assert_internal_server_error(response)
32
+ assert_response_status response, 500
33
+ end
34
+
35
+ def assert_response_status(response, status)
36
+ assert response.status == status, "Expected response to be a #{status}, but was a #{response.status}"
37
+ end
38
+
39
+ end
40
+
41
+ Rack::MockResponse.infect_an_assertion :assert_ok, :must_be_ok, :only_one_argument
42
+ Rack::MockResponse.infect_an_assertion :assert_created, :must_be_created, :only_one_argument
43
+ Rack::MockResponse.infect_an_assertion :assert_moved_permanently, :must_be_moved_permanently, :only_one_argument
44
+ Rack::MockResponse.infect_an_assertion :assert_bad_request, :must_be_bad_request, :only_one_argument
45
+ Rack::MockResponse.infect_an_assertion :assert_unauthorized, :must_be_unauthorized, :only_one_argument
46
+ Rack::MockResponse.infect_an_assertion :assert_not_found, :must_be_not_found, :only_one_argument
47
+ Rack::MockResponse.infect_an_assertion :assert_unprocessable_entity, :must_be_unprocessable_entity, :only_one_argument
48
+ Rack::MockResponse.infect_an_assertion :assert_internal_server_error, :must_be_internal_server_error, :only_one_argument
@@ -0,0 +1,31 @@
1
+ class MiniTest::Spec
2
+
3
+ include Rack::Test::Methods
4
+
5
+ def last_json_response
6
+ JSON.parse(last_response.body)
7
+ end
8
+
9
+ def get_json(path, params = {})
10
+ json_request :get, path, params
11
+ end
12
+
13
+ def post_json(path, params = {})
14
+ json_request :post, path, params
15
+ end
16
+
17
+ def put_json(path, params = {})
18
+ json_request :put, path, params
19
+ end
20
+
21
+ def delete_json(path, params = {})
22
+ json_request :delete, path, params
23
+ end
24
+
25
+ private
26
+
27
+ def json_request(verb, path, params = {})
28
+ send verb, path, params.to_json, "CONTENT_TYPE" => "application/json"
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Minitest
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack-minitest/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rack-minitest"
8
+ gem.version = Rack::Minitest::VERSION
9
+ gem.authors = ["Brandon Weiss"]
10
+ gem.email = ["brandon@anti-pattern.com"]
11
+ gem.description = %q{rack-minitest = rack-test + MiniTest}
12
+ gem.summary = %q{rack-minitest = rack-test + MiniTest}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "json"
21
+ gem.add_dependency "rack-test"
22
+ gem.add_dependency "minitest"
23
+
24
+ gem.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ def stub_app(status_code)
4
+ lambda { |env| [status_code, {}, [""]] }
5
+ end
6
+
7
+ describe MiniTest::Spec do
8
+
9
+ it "should have a spec-style matcher for an ok response" do
10
+ def app; stub_app(200); end
11
+
12
+ get "/"
13
+ last_response.must_be_ok
14
+ end
15
+
16
+ it "should have a spec-style matcher for a created response" do
17
+ def app; stub_app(201); end
18
+
19
+ get "/"
20
+ last_response.must_be_created
21
+ end
22
+
23
+ it "should have a spec-style matcher for a moved permanently response" do
24
+ def app; stub_app(301); end
25
+
26
+ get "/"
27
+ last_response.must_be_moved_permanently
28
+ end
29
+
30
+ it "should have a spec-style matcher for a bad request response" do
31
+ def app; stub_app(400); end
32
+
33
+ get "/"
34
+ last_response.must_be_bad_request
35
+ end
36
+
37
+ it "should have a spec-style matcher for an unauthorized response" do
38
+ def app; stub_app(401); end
39
+
40
+ get "/"
41
+ last_response.must_be_unauthorized
42
+ end
43
+
44
+ it "should have a spec-style matcher for a not found response" do
45
+ def app; stub_app(404); end
46
+
47
+ get "/"
48
+ last_response.must_be_not_found
49
+ end
50
+
51
+ it "should have a spec-style matcher for an unprocessable entity response" do
52
+ def app; stub_app(422); end
53
+
54
+ get "/"
55
+ last_response.must_be_unprocessable_entity
56
+ end
57
+
58
+ it "should have a spec-style matcher for an internal server error response" do
59
+ def app; stub_app(500); end
60
+
61
+ get "/"
62
+ last_response.must_be_internal_server_error
63
+ end
64
+
65
+ end
data/test/spec_test.rb ADDED
@@ -0,0 +1,39 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ describe MiniTest::Spec do
4
+
5
+ def app
6
+ json = { "foo" => "bar" }.to_json
7
+ lambda { |env| [200, { "Content-Type" => "text/html" }, [json]] }
8
+ end
9
+
10
+ it "should include Rack::Test::Methods" do
11
+ assert MiniTest::Spec.include? Rack::Test::Methods
12
+ end
13
+
14
+ it "should parse JSON responses" do
15
+ get "/"
16
+ last_json_response.must_equal({ "foo" => "bar" })
17
+ end
18
+
19
+ it "should get as JSON" do
20
+ get_json "/"
21
+ assert_equal "application/json", last_request.env["CONTENT_TYPE"]
22
+ end
23
+
24
+ it "should post as JSON" do
25
+ post_json "/"
26
+ assert_equal "application/json", last_request.env["CONTENT_TYPE"]
27
+ end
28
+
29
+ it "should put as JSON" do
30
+ put_json "/"
31
+ assert_equal "application/json", last_request.env["CONTENT_TYPE"]
32
+ end
33
+
34
+ it "should delete as JSON" do
35
+ delete_json "/"
36
+ assert_equal "application/json", last_request.env["CONTENT_TYPE"]
37
+ end
38
+
39
+ end
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.require :default
4
+
5
+ require "rack/test"
6
+ require "minitest/autorun"
7
+
8
+ require "json"
9
+ require "rack-minitest/assertions"
10
+ require "rack-minitest/spec"
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-minitest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Weiss
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack-test
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: rack-minitest = rack-test + MiniTest
79
+ email:
80
+ - brandon@anti-pattern.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/rack-minitest.rb
91
+ - lib/rack-minitest/assertions.rb
92
+ - lib/rack-minitest/spec.rb
93
+ - lib/rack-minitest/version.rb
94
+ - rack-minitest.gemspec
95
+ - test/assertions_test.rb
96
+ - test/spec_test.rb
97
+ - test/test_helper.rb
98
+ homepage: ''
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.23
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: rack-minitest = rack-test + MiniTest
122
+ test_files:
123
+ - test/assertions_test.rb
124
+ - test/spec_test.rb
125
+ - test/test_helper.rb