oktobertest 0.0.1 → 0.1.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: 2766bd05820c2140c972c6cb72d2a9bf08f0034f
4
- data.tar.gz: 536b310425a0d6b4b845c36ee2500a1720044313
3
+ metadata.gz: 26c78afdc12b287e7fb1b42bc9df02edf9db80bc
4
+ data.tar.gz: 395c8827be0f81e2575b57238fbb15e7c716dd5d
5
5
  SHA512:
6
- metadata.gz: dac4ac71b09de1b9c7a4b59416bb374ef6f0bc4951c13f3a93c63e58fc93e22ea32489c1805cf0d160b68960e0c2c54e5a44976f0e479b20d4fec17275ff8612
7
- data.tar.gz: f565aab1347b5fa094d0a3e1efa251bae18e2a76f2f4aa633eb3cef45b86a5c6c5a7a208ba0b73edc9975bcf3b6ab76bdd980522d45225ab3414fd18f6a5b6fb
6
+ metadata.gz: 364372c78233456737c8b70ab2fd83ee3eb09d938c3b4ec4750848f811f2eaafc88be0240ecfd5abc54af6750d665035cb5d8a370f60f0ad0e0b11faa5465d85
7
+ data.tar.gz: 0decf196630dcf487feb0b3957b5abcae7246c87204cfd9106406d9963b65e3a29365934e529a7f52de233239047b6a7cb195d5b1070fa4f4e773d2f04d4dea8
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ - ruby-head
6
+ addons:
7
+ code_climate:
8
+ repo_token:
9
+ secure: "D9vSv0Zpxro5tqUneuwtDWQTkUl7ysaA0BN1A17/1l8/omoOSNSgyL+ras01uiquqYA2XmsUNM3PlS1mSKBfYLFpHneFKSL+lpo9gkYlJRY2Rchc5mZxTO/dPOGD3wB+ba1xunLpsG5SuHQB1p+gv09D8DmGG8Bkz+0Hn1RYx2o="
data/README.md CHANGED
@@ -14,7 +14,7 @@ and I thought: "It shouldn't be so difficult to make a test library".
14
14
  runs its own context.
15
15
  * Each `scope` is an instance of `Oktobertest::Scope`. Methods defined in a
16
16
  scope are copied into each `test` it contains.
17
- * Extensible: it's easy to add more assertions.
17
+ * Extensible: it's easy to add more assertions (See [oktobertest-contrib](https://github.com/patriciomacadden/oktobertest-contrib)).
18
18
 
19
19
  ## Installation
20
20
 
@@ -92,29 +92,59 @@ module Oktobertest
92
92
  end
93
93
  ```
94
94
 
95
- ### Running the test suite
95
+ ### Running a test suite
96
96
 
97
- You can run the test suite using `rake` or the `ok` command.
97
+ You can run a test suite using `rake` or `ruby`.
98
98
 
99
99
  Using `rake`:
100
100
 
101
101
  ```ruby
102
- require 'oktobertest'
102
+ require 'rake/testtask'
103
103
 
104
- task :test do
105
- Oktobertest.run Dir['test/*_test.rb']
104
+ Rake::TestTask.new do |t|
105
+ t.libs << 'test'
106
+ t.pattern = 'test/*_test.rb'
106
107
  end
107
108
 
108
109
  task default: :test
109
110
  ```
110
111
 
111
- Using `ok`:
112
+ Using `ruby`:
112
113
 
113
114
  ```bash
114
- $ ok test/*_test.rb
115
+ $ ruby -r oktobertest test/*_test.rb
115
116
  ```
116
117
 
117
- Please check the default options by running `ok`.
118
+ When using `ruby` directly, you can specify two options: `--scope` and `--test`.
119
+
120
+ ```bash
121
+ $ ruby -r oktobertest test/*_test.rb --test 'test this'
122
+ ```
123
+
124
+ ### Testing Rack applications
125
+
126
+ Pretty simple:
127
+
128
+ ```ruby
129
+ require 'rack/test'
130
+
131
+ module Oktobertest
132
+ class Test
133
+ include Rack::Test::Methods
134
+
135
+ def app
136
+ Proc.new { |env| [200, {}, ['hello world']] }
137
+ end
138
+ end
139
+ end
140
+
141
+ scope 'rack app' do
142
+ test 'GET /' do
143
+ get '/'
144
+ assert last_response.status == 200
145
+ end
146
+ end
147
+ ```
118
148
 
119
149
  ## Contributing
120
150
 
data/Rakefile CHANGED
@@ -1,10 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
3
- require 'oktobertest'
4
-
5
- desc 'Run the tests'
6
- task :test do
7
- Oktobertest.run Dir['test/*_test.rb']
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/*_test.rb'
8
7
  end
9
8
 
10
9
  task default: :test
data/lib/oktobertest.rb CHANGED
@@ -1,43 +1,35 @@
1
+ require 'clap'
2
+
1
3
  module Oktobertest
2
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
3
5
 
4
6
  TestFailed = Class.new StandardError
5
7
  TestSkipped = Class.new StandardError
6
8
 
7
- def self.run(files)
8
- files.each { |file| load file }
9
+ def self.display_errors
9
10
  puts
10
11
  errors.each do |error|
11
12
  case error
12
13
  when TestFailed
13
- file, line, _ = error.backtrace[2].split(':')
14
+ file, line, _ = error.backtrace[2].split ':'
14
15
  print "\nerror: #{error.message}"
15
16
  when TestSkipped
16
- file, line, _ = error.backtrace[1].split(':')
17
+ file, line, _ = error.backtrace[1].split ':'
17
18
  print "\nskip"
18
- print ": #{error.message}" unless error.message == error.class.name
19
19
  else
20
- file, line, _ = error.backtrace[0].split(':')
20
+ file, line, _ = error.backtrace[0].split ':'
21
21
  print "\nerror: #{error.message}"
22
22
  end
23
23
  print "\nfile: #{file}\nline: #{line}\n"
24
24
  end
25
25
  end
26
26
 
27
- def self.run_test=(name)
28
- @run_test = name
29
- end
30
-
31
- def self.run_test
32
- @run_test
33
- end
34
-
35
- def self.run_scope=(name)
36
- @run_scope = name
27
+ def self.errors
28
+ @errors ||= []
37
29
  end
38
30
 
39
- def self.run_scope
40
- @run_scope
31
+ def self.options
32
+ @options ||= {}
41
33
  end
42
34
 
43
35
  module Assertions
@@ -60,8 +52,8 @@ module Oktobertest
60
52
  raise TestFailed, message
61
53
  end
62
54
 
63
- def skip(message = nil)
64
- raise TestSkipped, message
55
+ def skip
56
+ raise TestSkipped
65
57
  end
66
58
  end
67
59
 
@@ -75,12 +67,16 @@ module Oktobertest
75
67
  instance_eval &@block
76
68
  end
77
69
 
70
+ def run?
71
+ !Oktobertest.options[:run_scope] || Oktobertest.options[:run_scope] == @name
72
+ end
73
+
78
74
  protected
79
75
 
80
76
  def test(name = nil, &block)
81
- if !Oktobertest.run_test || Oktobertest.run_test == name
82
- test = Test.new(name, &block)
83
- singleton_methods.each { |m| test.define_singleton_method m, &method(m) }
77
+ test = Test.new name, &block
78
+ public_methods(false).reject { |m| m == :run || m == :run? }.each { |m| test.define_singleton_method m, &method(m) }
79
+ if test.run?
84
80
  @setup.each { |b| test.instance_eval &b }
85
81
  test.run
86
82
  @teardown.each { |b| test.instance_eval &b }
@@ -96,13 +92,11 @@ module Oktobertest
96
92
  end
97
93
 
98
94
  def scope(name = nil, &block)
99
- if !Oktobertest.run_scope || Oktobertest.run_scope == name
100
- scope = Scope.new(name, &block)
101
- singleton_methods.each { |m| scope.define_singleton_method m, &method(m) }
102
- @setup.each { |b| scope.setup &b }
103
- @teardown.each { |b| scope.teardown &b }
104
- scope.run
105
- end
95
+ scope = Scope.new name, &block
96
+ singleton_methods.each { |m| scope.define_singleton_method m, &method(m) }
97
+ @setup.each { |b| scope.setup &b }
98
+ @teardown.each { |b| scope.teardown &b }
99
+ scope.run if scope.run?
106
100
  end
107
101
  end
108
102
 
@@ -117,28 +111,32 @@ module Oktobertest
117
111
  instance_eval &@block
118
112
  print '.'
119
113
  rescue TestFailed => error
120
- Oktobertest.errors << error
121
114
  print 'F'
122
115
  rescue TestSkipped => error
123
- Oktobertest.errors << error
124
116
  print 'S'
125
117
  rescue StandardError => error
126
- Oktobertest.errors << error
127
118
  print 'E'
119
+ ensure
120
+ Oktobertest.errors << error unless error.nil?
128
121
  end
129
- end
130
122
 
131
- private
132
-
133
- def self.errors
134
- @errors ||= []
123
+ def run?
124
+ !Oktobertest.options[:run_test] || Oktobertest.options[:run_test] == @name
125
+ end
135
126
  end
136
127
  end
137
128
 
138
129
  module Kernel
130
+ private
131
+
139
132
  def scope(name = nil, &block)
140
- if !Oktobertest.run_scope || Oktobertest.run_scope == name
141
- Oktobertest::Scope.new(name, &block).run
142
- end
133
+ scope = Oktobertest::Scope.new name, &block
134
+ scope.run if scope.run?
143
135
  end
144
136
  end
137
+
138
+ Clap.run ARGV,
139
+ '--scope' => ->(name) { Oktobertest.options[:run_scope] = name },
140
+ '--test' => ->(name) { Oktobertest.options[:run_test] = name }
141
+
142
+ at_exit { Oktobertest.display_errors }
data/oktobertest.gemspec CHANGED
@@ -19,6 +19,7 @@ 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 'codeclimate-test-reporter'
22
23
  spec.add_development_dependency 'rake'
23
24
 
24
25
  spec.add_runtime_dependency 'clap', '~> 1.0.0'
@@ -1,43 +1,35 @@
1
+ require 'helper'
2
+
1
3
  scope 'assert' do
2
4
  test 'passes if the value is true' do
3
5
  assert true
4
6
  end
5
7
 
6
8
  test 'fails if the value is false' do
7
- assert_raises Oktobertest::TestFailed do
8
- assert false
9
- end
9
+ assert_raises(Oktobertest::TestFailed) { assert false }
10
10
  end
11
11
  end
12
12
 
13
13
  scope 'assert_raises' do
14
14
  test 'passes if the block raises the given exception' do
15
- assert_raises RuntimeError do
16
- raise RuntimeError
17
- end
15
+ assert_raises(RuntimeError) { raise RuntimeError }
18
16
  end
19
17
 
20
18
  test 'fails if the block does not raise the given exception' do
21
19
  assert_raises Oktobertest::TestFailed do
22
- assert_raises RuntimeError do
23
- raise ArgumentError
24
- end
20
+ assert_raises(RuntimeError) { raise ArgumentError }
25
21
  end
26
22
  end
27
23
  end
28
24
 
29
25
  scope 'flunk' do
30
26
  test 'raises Oktobertest::TestFailed exception' do
31
- assert_raises Oktobertest::TestFailed do
32
- flunk
33
- end
27
+ assert_raises(Oktobertest::TestFailed) { flunk }
34
28
  end
35
29
  end
36
30
 
37
31
  scope 'skip' do
38
32
  test 'raises Oktobertest::TestSkipped exception' do
39
- assert_raises Oktobertest::TestSkipped do
40
- skip
41
- end
33
+ assert_raises(Oktobertest::TestSkipped) { skip }
42
34
  end
43
35
  end
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope do
2
4
  test { raise RuntimeError }
3
5
  end
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope do
2
4
  test { assert false }
3
5
  end
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope 'run this' do
2
4
  test 'run this' do
3
5
  assert true
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope do
2
4
  test 'run this' do
3
5
  assert true
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope do
2
4
  test { skip }
3
5
  end
@@ -1,3 +1,5 @@
1
+ require 'oktobertest'
2
+
1
3
  scope do
2
4
  test { assert true }
3
5
  end
data/test/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'codeclimate-test-reporter'
2
+ SimpleCov.command_name 'Unit tests'
3
+ CodeClimate::TestReporter.start
4
+
5
+ require 'oktobertest'
@@ -1,7 +1,9 @@
1
+ require 'helper'
2
+
1
3
  scope do
2
4
  test 'successful run' do
3
5
  expected = ".\n"
4
- output = %x(bin/ok test/fixtures/successful_test.rb)
6
+ output = %x(ruby test/fixtures/successful_test.rb)
5
7
  assert expected == output
6
8
  end
7
9
 
@@ -11,9 +13,9 @@ E
11
13
 
12
14
  error: RuntimeError
13
15
  file: test/fixtures/error_test.rb
14
- line: 2
16
+ line: 4
15
17
  EOS
16
- output = %x(bin/ok test/fixtures/error_test.rb)
18
+ output = %x(ruby test/fixtures/error_test.rb)
17
19
  assert expected == output
18
20
  end
19
21
 
@@ -23,9 +25,9 @@ F
23
25
 
24
26
  error: condition is not true: false
25
27
  file: test/fixtures/failing_test.rb
26
- line: 2
28
+ line: 4
27
29
  EOS
28
- output = %x(bin/ok test/fixtures/failing_test.rb)
30
+ output = %x(ruby test/fixtures/failing_test.rb)
29
31
  assert expected == output
30
32
  end
31
33
 
@@ -35,21 +37,21 @@ S
35
37
 
36
38
  skip
37
39
  file: test/fixtures/skipped_test.rb
38
- line: 2
40
+ line: 4
39
41
  EOS
40
- output = %x(bin/ok test/fixtures/skipped_test.rb)
42
+ output = %x(ruby test/fixtures/skipped_test.rb)
41
43
  assert expected == output
42
44
  end
43
45
 
44
46
  test 'run only one scope' do
45
47
  expected = "..\n"
46
- output = %x(bin/ok -s 'run this' test/fixtures/run_scope_test.rb)
48
+ output = %x(ruby test/fixtures/run_scope_test.rb --scope 'run this')
47
49
  assert expected == output
48
50
  end
49
51
 
50
52
  test 'run only one test' do
51
53
  expected = ".\n"
52
- output = %x(bin/ok -t 'run this' test/fixtures/run_test_test.rb)
54
+ output = %x(ruby test/fixtures/run_test_test.rb --test 'run this')
53
55
  assert expected == output
54
56
  end
55
57
  end
data/test/scope_test.rb CHANGED
@@ -1,19 +1,33 @@
1
+ require 'helper'
2
+
1
3
  scope do
2
4
  def foo
3
5
  'foo'
4
6
  end
5
7
 
6
8
  test 'responds to foo' do
9
+ assert respond_to? :foo
7
10
  assert foo == 'foo'
8
11
  end
9
12
 
10
13
  scope do
11
- test 'responds to foo too' do
14
+ test 'responds to foo' do
15
+ assert respond_to? :foo
12
16
  assert foo == 'foo'
13
17
  end
14
18
  end
15
19
  end
16
20
 
21
+ scope do
22
+ test 'does not respond to foo' do
23
+ assert !respond_to?(:foo)
24
+ end
25
+
26
+ def foo
27
+ 'foo'
28
+ end
29
+ end
30
+
17
31
  scope do
18
32
  setup do
19
33
  @foo = 'foo'
@@ -24,13 +38,13 @@ scope do
24
38
  @bar = 'bar'
25
39
  end
26
40
 
27
- test 'foo and bar must be defined' do
41
+ test 'foo and bar are defined' do
28
42
  assert @foo == 'foo'
29
43
  assert @bar == 'bar'
30
44
  end
31
45
  end
32
46
 
33
- test 'foo must be defined and bar wont be' do
47
+ test 'foo is defined and bar is not' do
34
48
  assert @foo == 'foo'
35
49
  assert @bar.nil?
36
50
  end
data/test/setup_test.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'helper'
2
+
1
3
  scope do
2
4
  setup do
3
5
  @foo = 'foo'
@@ -8,7 +10,7 @@ scope do
8
10
  end
9
11
 
10
12
  scope do
11
- test 'foo is defined too' do
13
+ test 'foo is defined' do
12
14
  assert @foo == 'foo'
13
15
  end
14
16
  end
@@ -24,7 +26,7 @@ scope do
24
26
  @foo = 'bar'
25
27
  end
26
28
 
27
- test 'foo is not changed' do
29
+ test 'foo has not changed' do
28
30
  assert @foo == 'foo'
29
31
  end
30
32
  end
@@ -1,3 +1,5 @@
1
+ require 'helper'
2
+
1
3
  scope do
2
4
  setup do
3
5
  @foo = 'foo'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oktobertest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.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-03-25 00:00:00.000000000 Z
11
+ date: 2014-05-05 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: codeclimate-test-reporter
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: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -55,17 +69,16 @@ dependencies:
55
69
  description: Small test library
56
70
  email:
57
71
  - patriciomacadden@gmail.com
58
- executables:
59
- - ok
72
+ executables: []
60
73
  extensions: []
61
74
  extra_rdoc_files: []
62
75
  files:
63
76
  - ".gitignore"
77
+ - ".travis.yml"
64
78
  - Gemfile
65
79
  - LICENSE
66
80
  - README.md
67
81
  - Rakefile
68
- - bin/ok
69
82
  - lib/oktobertest.rb
70
83
  - oktobertest.gemspec
71
84
  - test/assertions_test.rb
@@ -75,6 +88,7 @@ files:
75
88
  - test/fixtures/run_test_test.rb
76
89
  - test/fixtures/skipped_test.rb
77
90
  - test/fixtures/successful_test.rb
91
+ - test/helper.rb
78
92
  - test/oktobertest_test.rb
79
93
  - test/scope_test.rb
80
94
  - test/setup_test.rb
@@ -111,6 +125,7 @@ test_files:
111
125
  - test/fixtures/run_test_test.rb
112
126
  - test/fixtures/skipped_test.rb
113
127
  - test/fixtures/successful_test.rb
128
+ - test/helper.rb
114
129
  - test/oktobertest_test.rb
115
130
  - test/scope_test.rb
116
131
  - test/setup_test.rb
data/bin/ok DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'usage: ok [-r lib] [-s scope] [-t test] [-v] file ...' if ARGV.empty?
4
-
5
- require 'clap'
6
- require_relative '../lib/oktobertest'
7
-
8
- files = Clap.run ARGV,
9
- '-r' => ->(file) { require file },
10
- '-s' => ->(name) { Oktobertest.run_scope = name },
11
- '-t' => ->(name) { Oktobertest.run_test = name },
12
- '-v' => -> { puts Oktobertest::VERSION }
13
-
14
- Oktobertest.run files if files.any?