cutest 1.2.2 → 1.2.3

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: 9bc022132fb8435fd081485e6649717148b2907f
4
- data.tar.gz: 51720cbf6e686d549bcb0db4b93aa427be3d1acc
3
+ metadata.gz: 9798d232220c6c693812a9db18c885a6e390b92a
4
+ data.tar.gz: b889afb1b6d810ec6dab549bb39ccd392573483b
5
5
  SHA512:
6
- metadata.gz: 030a88a3567dba1ac8d88e74c4121c921bc64ea1a0f9086764bc479ddd65ed7157dfe9026ca9bac7465546e57392866e3a1e8c9ec81f1d7c05f73425fb3bbc6c
7
- data.tar.gz: 355faf07ae61e2bac11b81943ce3953d4ac8a59eb0a043e4695f1afb7475ef0fa2f0c6c5f4708b517ca03a7e222f2aa4cac0ed64e24952d443971d590c265337
6
+ metadata.gz: 1ab94395a730e10588229f383ffa20515b8ac0816d9b381b86bd1029f3677d5a243cefead153d2f76db62831b84bb138f8a33945fee876b3aa0ff83b110a3436
7
+ data.tar.gz: 0529d8e1e97010ead35df62724de100b3ad3062ae1e570fdd217a19a6e90a7775a2bfa70bec523807661a224c1920d06ec503c562959dde0b11d0184568dcf47
@@ -1,3 +1,13 @@
1
+ 1.2.3 - 2015-12-04
2
+ ==================
3
+
4
+ * `assert_raise` now works with lower-level exceptions.
5
+
6
+ * `assert` can now receive a custom failure message, which should help write
7
+ better custom assertions.
8
+
9
+ * `cutest -v` now exits after printing the version number.
10
+
1
11
  1.2.2 - 2014-11-05
2
12
  ==================
3
13
 
@@ -0,0 +1,6 @@
1
+ TESTS=$(shell ls test/*.rb)
2
+
3
+ test:
4
+ ruby -W2 bin/cutest $(TESTS)
5
+
6
+ .PHONY: test
@@ -1,6 +1,8 @@
1
1
  Cutest
2
2
  =======
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/cutest.svg)](https://badge.fury.io/rb/cutest)
5
+
4
6
  Forking tests.
5
7
 
6
8
  Description
@@ -38,6 +40,10 @@ equal; and `assert_raise`, that executes a passed block and compares the raised
38
40
  exception to the expected one. In all cases, if the expectation is no met, an
39
41
  `AssertionFailed` exception is raised.
40
42
 
43
+ You can customize the output of `assert` by providing a second argument with
44
+ a string you want to get as an error report if the assertion is not fulfilled.
45
+ This can also be used as a simple building block to build custom assertions.
46
+
41
47
  Usage
42
48
  -----
43
49
 
@@ -47,83 +53,99 @@ In your terminal:
47
53
 
48
54
  In your tests:
49
55
 
50
- setup do
51
- {:a => 23, :b => 43}
52
- end
56
+ ````ruby
57
+ setup do
58
+ {:a => 23, :b => 43}
59
+ end
53
60
 
54
- test "should receive the result of the setup block as a parameter" do |params|
55
- assert params == {:a => 23, :b => 43}
56
- end
61
+ test "should receive the result of the setup block as a parameter" do |params|
62
+ assert params == {:a => 23, :b => 43}
63
+ end
57
64
 
58
- test "should evaluate the setup block before each test" do |params|
59
- params[:a] = nil
60
- end
65
+ test "should evaluate the setup block before each test" do |params|
66
+ params[:a] = nil
67
+ end
61
68
 
62
- test "should preserve the original values from the setup" do |params|
63
- assert 23 == params[:a]
64
- end
69
+ test "should preserve the original values from the setup" do |params|
70
+ assert 23 == params[:a]
71
+ end
72
+ ```
65
73
 
66
74
  An example working with a prepare block:
75
+ ````ruby
76
+ prepare do
77
+ Ohm.flush
78
+ end
67
79
 
68
- prepare do
69
- Ohm.flush
70
- end
80
+ setup do
81
+ Ohm.redis.get("foo")
82
+ end
71
83
 
72
- setup do
73
- Ohm.redis.get("foo")
74
- end
75
-
76
- test do |foo|
77
- assert foo.nil?
78
- end
84
+ test do |foo|
85
+ assert foo.nil?
86
+ end
87
+ ````
79
88
 
80
89
  And working with scopes:
81
-
82
- setup do
83
- @foo = true
84
- end
85
-
86
- @bar = true
87
-
88
- scope do
89
- test "should not share instance variables" do |foo|
90
- assert !defined?(@foo)
91
- assert !defined?(@bar)
92
- assert foo == true
93
- end
94
- end
90
+ ````ruby
91
+ setup do
92
+ @foo = true
93
+ end
94
+
95
+ @bar = true
96
+
97
+ scope do
98
+ test "should not share instance variables" do |foo|
99
+ assert !defined?(@foo)
100
+ assert !defined?(@bar)
101
+ assert foo == true
102
+ end
103
+ end
104
+ ````
95
105
 
96
106
  The tests in these two examples will pass.
97
107
 
98
108
  Unlike other testing frameworks, Cutest does not compile all the tests before
99
109
  running them.
100
110
 
111
+ A simple example for adding a custom `empty` assertion:
112
+ ````ruby
113
+ def assert_empty(string)
114
+ assert(string.empty?, "not empty")
115
+ end
116
+
117
+ test "failed custom assertion" do
118
+ assert_empty "foo"
119
+ end
120
+ ````
121
+
101
122
  Handling errors
102
123
  ---------------
103
124
 
104
125
  If you get an error when running the tests, this is what you will see:
105
-
106
- Exception: assert_equal 24, params[:a] # 24 != 23
107
- test/setup.rb +14
108
-
126
+ ````bash
127
+ Exception: assert_equal 24, params[:a] # 24 != 23
128
+ test/setup.rb +14
129
+ ````
109
130
  Running the build
110
131
  -----------------
111
132
 
112
133
  Using Rake:
134
+ ````ruby
135
+ task :test do
136
+ exec "cutest test/*.rb"
137
+ end
113
138
 
114
- task :test do
115
- exec "cutest test/*.rb"
116
- end
117
-
118
- task :default => :test
139
+ task :default => :test
140
+ ````
119
141
 
120
142
  Using Make:
143
+ ````yml
144
+ .PHONY: test
121
145
 
122
- .PHONY: test
123
-
124
- test:
125
- cutest test/*.rb
126
-
146
+ test:
147
+ cutest test/*.rb
148
+ ````
127
149
  Command-line interface
128
150
  ----------------------
129
151
 
data/bin/cutest CHANGED
@@ -12,7 +12,7 @@ files = Clap.run ARGV,
12
12
  "-r" => lambda { |file| require file },
13
13
  "-o" => lambda { |name| cutest[:only] = name },
14
14
  "-s" => lambda { |name| cutest[:scope] = name },
15
- "-v" => lambda { puts Cutest::VERSION }
15
+ "-v" => lambda { puts Cutest::VERSION; exit }
16
16
 
17
17
  if files.any?
18
18
  success = Cutest.run(Dir[*files])
@@ -1,6 +1,6 @@
1
1
  class Cutest
2
2
  unless defined?(VERSION)
3
- VERSION = "1.2.2"
3
+ VERSION = "1.2.3"
4
4
  FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
5
5
  CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
6
6
  end
@@ -92,7 +92,7 @@ private
92
92
  Thread.current[:cutest]
93
93
  end
94
94
 
95
- # Create a class where the block will be evaluated. Recommended to improve
95
+ # Create an instance where the block will be evaluated. Recommended to improve
96
96
  # isolation between tests.
97
97
  def scope(name = nil, &block)
98
98
  if !cutest[:scope] || cutest[:scope] == name
@@ -149,34 +149,33 @@ private
149
149
  end
150
150
 
151
151
  # Assert that value is not nil or false.
152
- def assert(value)
153
- flunk("expression returned #{value.inspect}") unless value
152
+ def assert(value, msg = "expression returned #{value.inspect}")
153
+ flunk(msg) unless value
154
154
  success
155
155
  end
156
156
 
157
- # Assert that two values are equal.
158
- def assert_equal(value, other)
159
- flunk("#{value.inspect} != #{other.inspect}") unless value == other
160
- success
157
+ # Assert that actual and expected values are equal.
158
+ def assert_equal(actual, expected)
159
+ assert(actual == expected, "#{actual.inspect} != #{expected.inspect}")
161
160
  end
162
161
 
163
- # Assert that the block doesn't raise the expected exception.
162
+ # Assert that the block raises an expected exception.
164
163
  def assert_raise(expected = Exception)
165
164
  begin
166
165
  yield
167
- rescue => exception
166
+ rescue expected => exception
168
167
  exception
169
168
  ensure
170
- flunk("got #{exception.inspect} instead") unless exception.kind_of?(expected)
171
- success
169
+ assert(exception.kind_of?(expected), "got #{exception.inspect} instead")
172
170
  end
173
171
  end
174
172
 
175
173
  # Stop the tests and raise an error where the message is the last line
176
174
  # executed before flunking.
177
175
  def flunk(message = nil)
176
+ backtrace = caller.find { |line| line.include? 'top (required)' }
178
177
  exception = Cutest::AssertionFailed.new(message)
179
- exception.set_backtrace([caller[1]])
178
+ exception.set_backtrace(backtrace)
180
179
 
181
180
  raise exception
182
181
  end
@@ -1,9 +1,27 @@
1
+ test "catches default exception" do
2
+ assert_raise do
3
+ raise
4
+ end
5
+ end
6
+
1
7
  test "catches the right exception" do
2
8
  assert_raise(RuntimeError) do
3
9
  raise RuntimeError
4
10
  end
5
11
  end
6
12
 
13
+ test "catches exceptions lower than StandardError" do
14
+ assert_raise(NotImplementedError) do
15
+ raise NotImplementedError
16
+ end
17
+ end
18
+
19
+ test "raises if nothing raised" do
20
+ assert_raise(Cutest::AssertionFailed) do
21
+ assert_raise {}
22
+ end
23
+ end
24
+
7
25
  test "raises if the expectation is not met" do
8
26
  assert_raise(Cutest::AssertionFailed) do
9
27
  assert_raise(RuntimeError) do
@@ -20,3 +38,8 @@ test "returns the exception" do
20
38
  assert_equal "error", exception.message
21
39
  end
22
40
 
41
+ test "catches a custom exception" do
42
+ assert_raise do
43
+ raise Class.new(Exception)
44
+ end
45
+ end
@@ -1,6 +1,5 @@
1
1
  def assert_empty(string)
2
- flunk("not empty") unless string.empty?
3
- success
2
+ assert(string.empty?, "not empty")
4
3
  end
5
4
 
6
5
  test "failed custom assertion" do
@@ -0,0 +1,3 @@
1
+ test "failed with custom message" do
2
+ assert("hello".empty?, "not empty")
3
+ end
@@ -41,11 +41,23 @@ test "exit code of failed run" do
41
41
  assert $?.to_i != 0
42
42
  end
43
43
 
44
+ test "output of an assertion with custom message" do
45
+ expected = "\n" +
46
+ " test: failed with custom message\n" +
47
+ " line: assert(\"hello\".empty?, \"not empty\")\n" +
48
+ " file: test/fixtures/fail_custom_message.rb +2\n\n" +
49
+ "Cutest::AssertionFailed: not empty\n\n"
50
+
51
+ out = %x{./bin/cutest test/fixtures/fail_custom_message.rb}
52
+
53
+ assert_equal(expected, out)
54
+ end
55
+
44
56
  test "output of custom assertion" do
45
57
  expected = "\n" +
46
58
  " test: failed custom assertion\n" +
47
59
  " line: assert_empty \"foo\"\n" +
48
- " file: test/fixtures/fail_custom_assertion.rb +7\n\n" +
60
+ " file: test/fixtures/fail_custom_assertion.rb +6\n\n" +
49
61
  "Cutest::AssertionFailed: not empty\n\n"
50
62
 
51
63
  out = %x{./bin/cutest test/fixtures/fail_custom_assertion.rb}
@@ -88,3 +100,11 @@ test "runs by given scope and test names" do
88
100
 
89
101
  assert_equal 0, $?.to_i
90
102
  end
103
+
104
+ test "only prints the version" do
105
+ expected = "#{Cutest::VERSION}\n"
106
+
107
+ out = %x{./bin/cutest test/fixtures/success.rb -v}
108
+
109
+ assert_equal(expected, out)
110
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cutest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-05 00:00:00.000000000 Z
13
+ date: 2015-12-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: clap
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  description: Run tests in separate processes to avoid shared state.
@@ -36,11 +36,11 @@ executables:
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
- - ".gitignore"
39
+ - .gitignore
40
40
  - CHANGELOG.md
41
41
  - LICENSE
42
+ - Makefile
42
43
  - README.markdown
43
- - Rakefile
44
44
  - bin/cutest
45
45
  - cutest.gemspec
46
46
  - lib/cutest.rb
@@ -49,6 +49,7 @@ files:
49
49
  - test/assert_raise.rb
50
50
  - test/fixtures/exception.rb
51
51
  - test/fixtures/fail_custom_assertion.rb
52
+ - test/fixtures/fail_custom_message.rb
52
53
  - test/fixtures/failure.rb
53
54
  - test/fixtures/failure_in_loaded_file.rb
54
55
  - test/fixtures/only_run_given_scope_name.rb
@@ -68,17 +69,17 @@ require_paths:
68
69
  - lib
69
70
  required_ruby_version: !ruby/object:Gem::Requirement
70
71
  requirements:
71
- - - ">="
72
+ - - '>='
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  requirements:
76
- - - ">="
77
+ - - '>='
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
79
80
  requirements: []
80
81
  rubyforge_project:
81
- rubygems_version: 2.2.2
82
+ rubygems_version: 2.4.6
82
83
  signing_key:
83
84
  specification_version: 4
84
85
  summary: Forking tests.
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require File.expand_path("../lib/cutest", __FILE__)
2
-
3
- $VERBOSE = true
4
-
5
- task :test do
6
- Cutest.run(Dir["test/*.rb"])
7
- end
8
-
9
- task :default => :test