flunk 0.0.8 → 0.0.9

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/lib/flunk.rb CHANGED
@@ -4,8 +4,8 @@ class Flunk < ActionDispatch::IntegrationTest
4
4
 
5
5
  def self.test(resource, action, &block)
6
6
  new_proc = Proc.new do
7
- @before.call unless @before.nil?
8
7
  instance_eval(&block)
8
+ @before.call unless @before.nil?
9
9
  result
10
10
  @after.call unless @after.nil?
11
11
  end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+ require 'flunk'
3
+
4
+ class BananasTest < Flunk
5
+
6
+ setup do
7
+ end
8
+
9
+ # Write tests that should succeed to make sure the required functionality works.
10
+ test "Banana", "Create" do
11
+ desc "Create a Banana"
12
+ path "bananas"
13
+ method :post
14
+ status :created
15
+ body banana: { weight: 2 }
16
+ before {
17
+ p "before was called"
18
+ }
19
+ after {
20
+ p "after was called"
21
+ }
22
+ end
23
+
24
+
25
+ # Write a test that SHOULD fail to ensure your application handles bad requests gracefully.
26
+ # flunk "Banana", "Create", "Not found" do
27
+ # path "/bananas/10000"
28
+ # method :get
29
+ # status :not_found
30
+ # end
31
+
32
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: flunk
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Kirk
@@ -17,15 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - LICENSE
21
- - README.md
22
- - Rakefile
23
- - flunk.gemspec
24
20
  - lib/flunk.rb
25
21
  - lib/generators/flunk_test/USAGE
26
22
  - lib/generators/flunk_test/flunk_test_generator.rb
27
23
  - lib/generators/flunk_test/templates/flunk_test.rb
28
24
  - lib/tasks/flunk.rake
25
+ - test/integration/bananas_test.rb
26
+ - test/test_helper.rb
29
27
  homepage: https://github.com/mysterioustrousers/flunk
30
28
  licenses: []
31
29
  post_install_message:
@@ -50,4 +48,6 @@ rubygems_version: 1.8.23
50
48
  signing_key:
51
49
  specification_version: 3
52
50
  summary: A gem for testing Ruby on Rails web APIs by simulating a client.
53
- test_files: []
51
+ test_files:
52
+ - test/integration/bananas_test.rb
53
+ - test/test_helper.rb
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2010 Mysterious Trousers, LLC (http://www.mysterioustrousers.com)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
data/README.md DELETED
@@ -1,107 +0,0 @@
1
- Flunk
2
- =====
3
-
4
- A gem for testing Ruby on Rails web APIs by simulating a client.
5
-
6
-
7
- ### Installation
8
-
9
- In your Gemfile, add this line:
10
-
11
- gem "flunk"
12
-
13
- ### Description
14
-
15
- We write mostly JSON APIs using Rails, not your traditional web app, so we wanted a better way to test our JSON APIs. This is flunk.
16
-
17
- ### Usage
18
-
19
- In each test block you call a series of methods [`desc`, `path`, `method`, `username`, `password`, `body`, `status`, `assertions`] as necessary.
20
-
21
- `desc`: In the future, a documentation generator will be added and this will be used to determine if the test should be documented as an API method.
22
- `path`: The relative URL for the resource.
23
- `method`: :get, :post, :put or :delete
24
- `username`: For authentication using basic auth.
25
- `password`: For authentication using basic auth.
26
- `body`: The body of the request.
27
- `status`: This method actually acts like an assertion. It is what the status of the response SHOULD be. An error will be thrown if it doesn't match.
28
- `assertions`: A block of of assertions you call to verify the response was what it should have been.
29
-
30
- Once you call `assertions`, the request is fired and a `result` method is available within the assertions block containing the response.
31
-
32
- ### Example
33
-
34
- It's your typical rails integration test, but inherits from Flunk:
35
-
36
- class UsersTest < Flunk
37
-
38
- setup do
39
- @user = FactoryGirl.create(:user)
40
- end
41
-
42
- You write tests that SHOULD pass to test your app's basic functionality all works:
43
-
44
- test "User", "Create" do
45
- desc "Creating a new Langwich user."
46
- path "signup"
47
- method :post
48
- body user: attrs = FactoryGirl.attributes_for(:user)
49
- status :created
50
- before {
51
- assert_equal 0, user.languages.count
52
- }
53
- after {
54
- assert_equal result[:name], attrs[:name]
55
- assert_equal result[:username], attrs[:username]
56
- assert_equal result[:email], attrs[:email]
57
- assert_not_nil result[:api_token]
58
- user = User.find_by_api_token result[:api_token]
59
- assert_equal 1, user.languages.count
60
- }
61
- end
62
-
63
- test "User", "Log In With Email" do
64
- path "login"
65
- method :get
66
- body username: @user.email, password: @user.password
67
- status :ok
68
- after {
69
- assert_not_nil result[:api_token]
70
- }
71
- end
72
-
73
- test "User", "Read" do
74
- desc "Read a users information."
75
- path "account"
76
- method :get
77
- username @user.api_token
78
- status :ok
79
- end
80
-
81
-
82
- Then, write tests that SHOULDN'T pass to make sure your app rejects bad requests correctly/gracefully:
83
-
84
-
85
- flunk "User", "Create", "Missing username" do
86
- desc "Attempting to create a user without a username."
87
- path "signup"
88
- method :post
89
- body user: FactoryGirl.attributes_for(:user, username: nil)
90
- status :unprocessable_entity
91
- end
92
-
93
- flunk "User", "Create", "Username already taken" do
94
- path "signup"
95
- method :post
96
- body user: FactoryGirl.attributes_for(:user, username: @user.username)
97
- status :unprocessable_entity
98
- end
99
- end
100
-
101
- ### Generator
102
-
103
- To generate a flunk test:
104
-
105
- rails g generate flunk_test User
106
-
107
- This will create an integration test: test/integration/users_test.rb
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new do |t|
4
- t.libs << 'test'
5
- end
6
-
7
- desc "Run tests"
8
- task :default => :test
data/flunk.gemspec DELETED
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "flunk"
3
- s.version = "0.0.8"
4
- s.platform = Gem::Platform::RUBY
5
- s.authors = ["Adam Kirk"]
6
- s.email = %q{atomkirk@gmail.com}
7
- s.homepage = %q{https://github.com/mysterioustrousers/flunk}
8
- s.summary = %q{A gem for testing Ruby on Rails web APIs by simulating a client.}
9
- s.description = %q{A gem for testing Ruby on Rails web APIs by simulating a client.}
10
-
11
- s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
12
- s.test_files =`git ls-files -- test/*`.split("\n")
13
- s.require_paths = ["lib"]
14
-
15
- end