oktobertest-contrib 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +43 -18
- data/Rakefile +1 -1
- data/lib/oktobertest/assertions.rb +16 -6
- data/lib/oktobertest/capybara.rb +21 -0
- data/lib/oktobertest/contrib.rb +8 -1
- data/lib/oktobertest/contrib/version.rb +1 -1
- data/lib/oktobertest/rack/test.rb +15 -0
- data/oktobertest-contrib.gemspec +2 -0
- data/test/assertions_test.rb +34 -10
- data/test/capybara_test.rb +22 -0
- data/test/rack/test_test.rb +25 -10
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5495ebae0974da2d369afb60fef51b1d7e30259e
|
4
|
+
data.tar.gz: c91ad77a1316a118d87001c03042fc30d1a7bc7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb703ec9dfd4c37297edd0a7e1c16375f643feb55d240974d2d27e99e516492d7d38360f164087c6f664f597c15f80a486ab70dac58486642cf3035e6d81a4fc
|
7
|
+
data.tar.gz: cac489dbe2e8e0a910700c860988a7f75cb77ec8e734716ffc4952fd38ee849fc756f15fee66139e568a44c12c09576851d406d16cfd3f167db64bbabbcbd714
|
data/.travis.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.2
|
5
|
+
- ruby-head
|
6
|
+
addons:
|
7
|
+
code_climate:
|
8
|
+
repo_token:
|
9
|
+
secure: "FhQkscMwIl7a0AN5gTsWQ+x8cCyUVikMkxZ5GfsDP5URrVNYG+2z0kwtZP5XVFSFlbpALUS5f6i410UYd14sVVpb/CVK58ixQfeIPBDVGi5lYtUelfyUgrhiM9pJpAtnKBUntkh0vd5jW/+QCLMPqCZZj2gsw0BueHgL7OHcF48="
|
data/README.md
CHANGED
@@ -24,10 +24,18 @@ Or install it yourself as:
|
|
24
24
|
$ gem install oktobertest-contrib
|
25
25
|
```
|
26
26
|
|
27
|
+
### Optional dependencies
|
28
|
+
|
29
|
+
* [rack-test](https://github.com/brynary/rack-test) if you want to use
|
30
|
+
`oktobertest/rack/test`.
|
31
|
+
* [capybara](https://github.com/jnicklas/capybara) and
|
32
|
+
[poltergeist](https://github.com/teampoltergeist/poltergeist) if you want to use
|
33
|
+
`oktobertest/capybara`.
|
34
|
+
|
27
35
|
## Usage
|
28
36
|
|
29
37
|
`require` an extension to use it. If you want to use all of them, just
|
30
|
-
`require 'oktobertest
|
38
|
+
`require 'oktobertest/contrib'`.
|
31
39
|
|
32
40
|
## Available extensions
|
33
41
|
|
@@ -44,10 +52,6 @@ scope do
|
|
44
52
|
expected, actual = 1, 1
|
45
53
|
assert_equal expected, actual
|
46
54
|
end
|
47
|
-
|
48
|
-
test do
|
49
|
-
refute false
|
50
|
-
end
|
51
55
|
end
|
52
56
|
```
|
53
57
|
|
@@ -55,10 +59,14 @@ end
|
|
55
59
|
|
56
60
|
* `assert_equal(expected, actual, message)`: asserts that the expected and the
|
57
61
|
actual values are equal.
|
58
|
-
* `
|
59
|
-
|
60
|
-
* `
|
61
|
-
|
62
|
+
* `assert_includes(collection, item, message)`: asserts that the collection
|
63
|
+
includes the item.
|
64
|
+
* `assert_instance_of(klass, object, message)`: asserts that the object is an
|
65
|
+
instance of class.
|
66
|
+
* `assert_kind_of(klass, object, message)`: asserts that the object is kind of
|
67
|
+
class.
|
68
|
+
* `assert_matches(matcher, object, message)`: asserts that the object matches
|
69
|
+
the matcher.
|
62
70
|
|
63
71
|
### Rack related assertions
|
64
72
|
|
@@ -68,20 +76,16 @@ This extesion includes rack related assertions. To use it, just require it:
|
|
68
76
|
require 'oktobertest'
|
69
77
|
require 'oktobertest/rack/test'
|
70
78
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def app
|
76
|
-
Proc.new { |env| [200, {}, ['hello world']] }
|
77
|
-
end
|
79
|
+
scope do
|
80
|
+
setup do
|
81
|
+
@app = Proc.new { |env| [200, {}, ['hello world']] }
|
78
82
|
end
|
79
|
-
end
|
80
83
|
|
81
|
-
scope do
|
82
84
|
test 'GET /' do
|
83
85
|
get '/'
|
84
86
|
assert_status 200
|
87
|
+
# equivalent to:
|
88
|
+
# assert_equal 200, last_response.status
|
85
89
|
end
|
86
90
|
end
|
87
91
|
```
|
@@ -90,6 +94,27 @@ end
|
|
90
94
|
|
91
95
|
* `assert_status(status_code, message)`: asserts that the response status code
|
92
96
|
is equal to `status_code`.
|
97
|
+
* `assert_header(header, value, message)`: asserts that the response header
|
98
|
+
`header` is equal to `value`.
|
99
|
+
|
100
|
+
### Capybara
|
101
|
+
|
102
|
+
This extension includes automatic setup for
|
103
|
+
[Capybara](https://github.com/jnicklas/capybara).
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
require 'oktobertest'
|
107
|
+
require 'oktobertest/capybara'
|
108
|
+
|
109
|
+
Capybara.app = App
|
110
|
+
|
111
|
+
scope do
|
112
|
+
test 'works' do
|
113
|
+
visit '/'
|
114
|
+
assert page.has_content? 'hello world'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
93
118
|
|
94
119
|
## Contributing
|
95
120
|
|
data/Rakefile
CHANGED
@@ -5,14 +5,24 @@ module Oktobertest
|
|
5
5
|
assert expected == actual, message
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
message ||= "
|
10
|
-
|
8
|
+
def assert_includes(collection, item, message = nil)
|
9
|
+
message ||= "#{collection.inspect} does not include #{item}"
|
10
|
+
assert collection.include?(item), message
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
message ||= "
|
15
|
-
assert
|
13
|
+
def assert_instance_of(klass, object, message = nil)
|
14
|
+
message ||= "object is not instance of #{klass}"
|
15
|
+
assert object.instance_of?(klass), message
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_kind_of(klass, object, message = nil)
|
19
|
+
message ||= "object is not kind of #{klass}"
|
20
|
+
assert object.kind_of?(klass), message
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_matches(matcher, object, message = nil)
|
24
|
+
message ||= "#{object} does not match #{matcher}"
|
25
|
+
assert object =~ matcher, message
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/poltergeist'
|
3
|
+
|
4
|
+
module Oktobertest
|
5
|
+
class Scope
|
6
|
+
module Capybara
|
7
|
+
def initialize(name = nil, &block)
|
8
|
+
super
|
9
|
+
teardown { Capybara.reset_sessions! }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include Capybara
|
14
|
+
end
|
15
|
+
|
16
|
+
class Test
|
17
|
+
include Capybara::DSL
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Capybara.default_driver = :poltergeist
|
data/lib/oktobertest/contrib.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
1
3
|
module Oktobertest
|
2
4
|
module Assertions
|
3
5
|
def assert_status(status_code, message = nil)
|
4
6
|
message ||= "expected status code to be #{status_code}, got #{last_response.status} instead"
|
5
7
|
assert_equal status_code, last_response.status, message
|
6
8
|
end
|
9
|
+
|
10
|
+
def assert_header(header, value, message = nil)
|
11
|
+
message ||= "expected header #{header} to be #{value}, got #{last_response.headers[header]} instead"
|
12
|
+
assert_equal value, last_response.headers[header]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Test
|
17
|
+
include Rack::Test::Methods
|
18
|
+
|
19
|
+
def app
|
20
|
+
@app
|
21
|
+
end
|
7
22
|
end
|
8
23
|
end
|
data/oktobertest-contrib.gemspec
CHANGED
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'capybara'
|
22
23
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
|
+
spec.add_development_dependency 'poltergeist'
|
23
25
|
spec.add_development_dependency 'rack-test'
|
24
26
|
spec.add_development_dependency 'rake'
|
25
27
|
|
data/test/assertions_test.rb
CHANGED
@@ -10,22 +10,46 @@ scope 'assert_equal' do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
scope '
|
14
|
-
|
15
|
-
|
13
|
+
scope 'assert_includes' do
|
14
|
+
setup do
|
15
|
+
@collection = %w(one two three)
|
16
16
|
end
|
17
17
|
|
18
|
-
test '
|
19
|
-
|
18
|
+
test 'passes if collection.include? item' do
|
19
|
+
assert_includes @collection, 'one'
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'fails if !collection.include? item' do
|
23
|
+
assert_raises(Oktobertest::TestFailed) { assert_includes @collection, 'four' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
scope 'assert_instance_of' do
|
28
|
+
test 'passes if object.instance_of? klass' do
|
29
|
+
assert_instance_of Array, [1, 2, 3]
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'fails if !object.instance_of? klass' do
|
33
|
+
assert_raises(Oktobertest::TestFailed) { assert_instance_of Array, { one: 1 } }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
scope 'assert_kind_of' do
|
38
|
+
test 'passes if object.kind_of? klass' do
|
39
|
+
assert_kind_of StandardError, ArgumentError.new
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'fails if !object.kind_of? klass' do
|
43
|
+
assert_raises(Oktobertest::TestFailed) { assert_kind_of StandardError, ScriptError.new }
|
20
44
|
end
|
21
45
|
end
|
22
46
|
|
23
|
-
scope '
|
24
|
-
test 'passes if
|
25
|
-
|
47
|
+
scope 'assert_matches' do
|
48
|
+
test 'passes if object =~ matcher' do
|
49
|
+
assert_matches /123/, '123'
|
26
50
|
end
|
27
51
|
|
28
|
-
test 'fails if
|
29
|
-
assert_raises(Oktobertest::TestFailed) {
|
52
|
+
test 'fails if object !~ matcher' do
|
53
|
+
assert_raises(Oktobertest::TestFailed) { assert_matches /123/, '345' }
|
30
54
|
end
|
31
55
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
scope 'Capybara' do
|
4
|
+
scope 'if Capybara.app is defined' do
|
5
|
+
setup do
|
6
|
+
@app = ->(env) { [200, {}, ['hello world']] }
|
7
|
+
end
|
8
|
+
|
9
|
+
setup do
|
10
|
+
Capybara.app = @app
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'works' do
|
14
|
+
visit '/'
|
15
|
+
assert page.has_content? 'hello world'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'Capybara::DSL is included' do
|
20
|
+
assert self.class.included_modules.include? Capybara::DSL
|
21
|
+
end
|
22
|
+
end
|
data/test/rack/test_test.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
require 'rack/test'
|
2
1
|
require 'helper'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def app
|
9
|
-
Proc.new { |env| [200, {}, ['hello world']] }
|
10
|
-
end
|
3
|
+
scope 'assert_status' do
|
4
|
+
setup do
|
5
|
+
@app = Proc.new { |env| [200, {}, ['hello world']] }
|
11
6
|
end
|
12
|
-
end
|
13
7
|
|
14
|
-
scope 'assert_status' do
|
15
8
|
test "passes if the argument matches last response's status" do
|
16
9
|
get '/'
|
17
10
|
assert_status 200
|
@@ -22,3 +15,25 @@ scope 'assert_status' do
|
|
22
15
|
assert_raises(Oktobertest::TestFailed) { assert_status 404 }
|
23
16
|
end
|
24
17
|
end
|
18
|
+
|
19
|
+
scope 'assert_status' do
|
20
|
+
setup do
|
21
|
+
@app = Proc.new { |env| [200, { 'Content-Type' => 'text/plain' }, ['hello world']] }
|
22
|
+
end
|
23
|
+
|
24
|
+
test "passes if the argument matches last response's header" do
|
25
|
+
get '/'
|
26
|
+
assert_header 'Content-Type', 'text/plain'
|
27
|
+
end
|
28
|
+
|
29
|
+
test "fails if the argument does not match last response's header" do
|
30
|
+
get '/'
|
31
|
+
assert_raises(Oktobertest::TestFailed) { assert_header 'Content-Type', 'text/html' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
scope 'without setting @app' do
|
36
|
+
test 'fails' do
|
37
|
+
assert_raises(NoMethodError) { get '/' }
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oktobertest-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: codeclimate-test-reporter
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: poltergeist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rack-test
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,16 +116,19 @@ extensions: []
|
|
88
116
|
extra_rdoc_files: []
|
89
117
|
files:
|
90
118
|
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
91
120
|
- Gemfile
|
92
121
|
- LICENSE
|
93
122
|
- README.md
|
94
123
|
- Rakefile
|
95
124
|
- lib/oktobertest/assertions.rb
|
125
|
+
- lib/oktobertest/capybara.rb
|
96
126
|
- lib/oktobertest/contrib.rb
|
97
127
|
- lib/oktobertest/contrib/version.rb
|
98
128
|
- lib/oktobertest/rack/test.rb
|
99
129
|
- oktobertest-contrib.gemspec
|
100
130
|
- test/assertions_test.rb
|
131
|
+
- test/capybara_test.rb
|
101
132
|
- test/helper.rb
|
102
133
|
- test/rack/test_test.rb
|
103
134
|
homepage: ''
|
@@ -126,5 +157,6 @@ specification_version: 4
|
|
126
157
|
summary: Contributed Oktobertest extensions
|
127
158
|
test_files:
|
128
159
|
- test/assertions_test.rb
|
160
|
+
- test/capybara_test.rb
|
129
161
|
- test/helper.rb
|
130
162
|
- test/rack/test_test.rb
|