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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e328faecf46baaf4eb655634aca51ad82292b48f
4
- data.tar.gz: 1e624b96b8c8c1b04b23f23abf003348443c06dd
3
+ metadata.gz: 5495ebae0974da2d369afb60fef51b1d7e30259e
4
+ data.tar.gz: c91ad77a1316a118d87001c03042fc30d1a7bc7e
5
5
  SHA512:
6
- metadata.gz: 4b78d7004ebb1001b6a0c9925ea56c416f6e690ca60794cde5262cedc26d6bcfb34b30dc763bdba7f85285cda7735054f0d9a521de852dbb68727a6c839ed359
7
- data.tar.gz: febc75f2545bcd3a04057fbb9e9c84fc4ccda978d91d306a025a83c74a964eeee092de21f316c10165dc4b7df12a5ce2baa804e9eaf6ab7320d6e8667d25027d
6
+ metadata.gz: fb703ec9dfd4c37297edd0a7e1c16375f643feb55d240974d2d27e99e516492d7d38360f164087c6f664f597c15f80a486ab70dac58486642cf3035e6d81a4fc
7
+ data.tar.gz: cac489dbe2e8e0a910700c860988a7f75cb77ec8e734716ffc4952fd38ee849fc756f15fee66139e568a44c12c09576851d406d16cfd3f167db64bbabbcbd714
@@ -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-contrib'`.
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
- * `refute(value, message)`: refutes the expected value (ie. passes if value is
59
- false).
60
- * `refute_equal(expected, actual, message)`: refutes that the expected and the
61
- actual values are equal (ie. passes if expected and actual are not equal).
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
- module Oktobertest
72
- class Test
73
- include Rack::Test::Methods
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
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
- t.pattern = 'test/*_test.rb'
6
+ t.pattern = 'test/**/*_test.rb'
7
7
  end
8
8
 
9
9
  task default: :test
@@ -5,14 +5,24 @@ module Oktobertest
5
5
  assert expected == actual, message
6
6
  end
7
7
 
8
- def refute(value, message = nil)
9
- message ||= "condition is not false: #{value.inspect}"
10
- flunk message unless !value
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 refute_equal(expected, actual, message = nil)
14
- message ||= "#{expected} == #{actual}"
15
- assert expected != actual, message
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
@@ -1,3 +1,10 @@
1
1
  require 'oktobertest/assertions'
2
+ begin
3
+ require 'oktobertest/capybara'
4
+ rescue LoadError
5
+ end
2
6
  require 'oktobertest/contrib/version'
3
- require 'oktobertest/rack/test'
7
+ begin
8
+ require 'oktobertest/rack/test'
9
+ rescue LoadError
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Oktobertest
2
2
  module Contrib
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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
@@ -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
 
@@ -10,22 +10,46 @@ scope 'assert_equal' do
10
10
  end
11
11
  end
12
12
 
13
- scope 'refute' do
14
- test 'passes if the value is false' do
15
- refute false
13
+ scope 'assert_includes' do
14
+ setup do
15
+ @collection = %w(one two three)
16
16
  end
17
17
 
18
- test 'fails if the value is true' do
19
- assert_raises(Oktobertest::TestFailed) { refute true }
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 'refute_equal' do
24
- test 'passes if expected != actual' do
25
- refute_equal 1, 2
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 expected == actual' do
29
- assert_raises(Oktobertest::TestFailed) { refute_equal 1, 1 }
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
@@ -1,17 +1,10 @@
1
- require 'rack/test'
2
1
  require 'helper'
3
2
 
4
- module Oktobertest
5
- class Test
6
- include Rack::Test::Methods
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.1.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-05-31 00:00:00.000000000 Z
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