shared_tests 0.0.2 → 0.0.3
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/Rakefile +10 -0
- data/Readme.md +50 -46
- data/lib/shared_tests.rb +3 -7
- data/lib/shared_tests/version.rb +1 -1
- data/test/shared_tests_test.rb +15 -28
- metadata +8 -6
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -1,84 +1,88 @@
|
|
1
1
|
# Shared tests
|
2
2
|
|
3
|
-
Shared tests is
|
4
|
-
easily, using a little pattern and a commodity DSL.
|
3
|
+
Shared tests is an assertion for Test::Unit that let's you assert the behavior shared by your objects in a more readable way.
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
gem install shared_tests
|
9
|
-
|
10
|
-
## Usage
|
11
|
-
|
12
|
-
You want to test this behavior shared by some of your objects.
|
5
|
+
Two objects have common behavior
|
13
6
|
|
14
7
|
```ruby
|
15
|
-
|
16
|
-
|
17
|
-
"a programming motherfucker"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
```
|
21
|
-
|
22
|
-
Your Hacker and SysAdmin instances are programming motherfuckers.
|
8
|
+
class StringTest < Test::Unit::TestCase
|
9
|
+
include SharedTests
|
23
10
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
11
|
+
def setup
|
12
|
+
@subject = "I have length"
|
13
|
+
end
|
28
14
|
|
29
|
-
|
30
|
-
include ProgrammingMotherfucker
|
15
|
+
assert_tests :of => :length
|
31
16
|
end
|
32
|
-
```
|
33
17
|
|
34
|
-
|
35
|
-
|
18
|
+
class ArrayTest < Test::Unit::TestCase
|
19
|
+
include SharedTests
|
36
20
|
|
37
|
-
|
38
|
-
|
39
|
-
# write your tests as usual
|
40
|
-
def test_is_a_programming_motherfucker?
|
41
|
-
assert @me.what_am_i? == "a programming motherfucker"
|
21
|
+
def setup
|
22
|
+
@subject = [:i, :have, :length]
|
42
23
|
end
|
24
|
+
|
25
|
+
assert_shared_tests :of => :length
|
43
26
|
end
|
44
27
|
```
|
45
28
|
|
46
|
-
|
29
|
+
The name of the module where you have the tests for the shared behavior must end with the word Tests. Also make sure you have set up all variables used in the examples.
|
47
30
|
|
48
31
|
```ruby
|
49
|
-
|
50
|
-
|
32
|
+
module LengthTests
|
33
|
+
def test_length_is_not_zero
|
34
|
+
assert @subject.length > 0
|
35
|
+
end
|
51
36
|
|
52
|
-
|
53
|
-
|
54
|
-
@me = Hacker.new
|
37
|
+
def test_is_not_empty?
|
38
|
+
assert false == @subject.empty?
|
55
39
|
end
|
56
40
|
end
|
57
41
|
```
|
58
42
|
|
59
|
-
|
43
|
+
It's all about readability, the same without using the assertion would be
|
60
44
|
|
61
45
|
```ruby
|
62
|
-
class
|
46
|
+
class StringTest < Test::Unit::TestCase
|
63
47
|
include SharedTests
|
64
48
|
|
65
|
-
|
66
|
-
|
67
|
-
@me = SysAdmin.new
|
49
|
+
def setup
|
50
|
+
@subject = "I have length"
|
68
51
|
end
|
52
|
+
|
53
|
+
include LengthTests
|
69
54
|
end
|
70
55
|
```
|
71
56
|
|
57
|
+
And the results
|
58
|
+
|
59
|
+
```
|
60
|
+
$ rake test
|
61
|
+
/home/joahking/.rvm/rubies/ruby-1.8.7-p302/bin/ruby -I"lib:test" -I"/home/joahking/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.9.0/lib" "/home/joahking/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.9.0/lib/rake/rake_test_loader.rb" "test/shared_tests_test.rb"
|
62
|
+
Loaded suite /home/joahking/.rvm/gems/ruby-1.8.7-p302/gems/rake-0.9.0/lib/rake/rake_test_loader
|
63
|
+
Started
|
64
|
+
....
|
65
|
+
Finished in 0.00036 seconds.
|
66
|
+
|
67
|
+
4 tests, 4 assertions, 0 failures, 0 errors
|
68
|
+
```
|
69
|
+
|
70
|
+
## Installation
|
71
|
+
|
72
|
+
gem install shared_tests
|
73
|
+
|
72
74
|
## TODO
|
73
75
|
|
74
76
|
* make it use Minitest
|
75
|
-
*
|
76
|
-
|
77
|
-
|
77
|
+
* make it work with shoulda?
|
78
|
+
|
79
|
+
## Build status
|
80
|
+
|
81
|
+
[](http://travis-ci.org/joahking/shared_tests)
|
78
82
|
|
79
83
|
## Thanks
|
80
84
|
|
81
|
-
* [Jorge Días](https://github.com/diasjorge) for useful tips.
|
85
|
+
* [Jorge Días](https://github.com/diasjorge) for useful tips and pair programming this.
|
82
86
|
|
83
87
|
## License
|
84
88
|
|
data/lib/shared_tests.rb
CHANGED
@@ -3,18 +3,14 @@ require "active_support/inflector"
|
|
3
3
|
|
4
4
|
module SharedTests
|
5
5
|
def self.included(base)
|
6
|
-
base.send :extend,
|
6
|
+
base.send :extend, ClassMethods
|
7
7
|
end
|
8
8
|
|
9
|
-
module
|
9
|
+
module ClassMethods
|
10
|
+
|
10
11
|
def assert_shared_tests(options = {}, &block)
|
11
12
|
shared_test = options.delete(:of)
|
12
13
|
include "#{shared_test.to_s.camelize}Tests".constantize
|
13
|
-
|
14
|
-
define_method(:setup) do
|
15
|
-
super()
|
16
|
-
instance_eval &block
|
17
|
-
end
|
18
14
|
end
|
19
15
|
alias_method :assert_tests, :assert_shared_tests
|
20
16
|
|
data/lib/shared_tests/version.rb
CHANGED
data/test/shared_tests_test.rb
CHANGED
@@ -1,45 +1,32 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/shared_tests')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
"a programming motherfucker"
|
4
|
+
module LengthTests
|
5
|
+
def test_length_is_not_zero
|
6
|
+
assert @subject.length > 0
|
8
7
|
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# hacker instances are programming motherfuckers
|
12
|
-
class Hacker
|
13
|
-
include ProgrammingMotherfucker
|
14
|
-
end
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
include ProgrammingMotherfucker
|
19
|
-
end
|
20
|
-
|
21
|
-
# declaring the shared behavior test examples
|
22
|
-
module ProgrammingMotherfuckerTests
|
23
|
-
def test_is_a_programming_motherfucker?
|
24
|
-
assert @me.what_am_i? == "a programming motherfucker"
|
9
|
+
def test_is_not_empty?
|
10
|
+
assert false == @subject.empty?
|
25
11
|
end
|
26
12
|
end
|
27
13
|
|
28
|
-
|
29
|
-
class HackerTest < Test::Unit::TestCase
|
14
|
+
class StringTest < Test::Unit::TestCase
|
30
15
|
include SharedTests
|
31
16
|
|
32
|
-
|
33
|
-
@
|
17
|
+
def setup
|
18
|
+
@subject = "I have length"
|
34
19
|
end
|
20
|
+
|
21
|
+
assert_tests :of => :length
|
35
22
|
end
|
36
23
|
|
37
|
-
|
38
|
-
class SysAdminUsesShortHandTest < Test::Unit::TestCase
|
24
|
+
class ArrayTest < Test::Unit::TestCase
|
39
25
|
include SharedTests
|
40
26
|
|
41
|
-
|
42
|
-
|
43
|
-
@me = SysAdmin.new
|
27
|
+
def setup
|
28
|
+
@subject = [:i, :have, :length]
|
44
29
|
end
|
30
|
+
|
31
|
+
assert_shared_tests :of => :length
|
45
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shared_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joaquin Rivera Padron
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activesupport
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- lib/shared_tests/version.rb
|
51
52
|
- shared_tests.gemspec
|
52
53
|
- test/shared_tests_test.rb
|
54
|
+
has_rdoc: true
|
53
55
|
homepage: ""
|
54
56
|
licenses: []
|
55
57
|
|
@@ -79,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
81
|
requirements: []
|
80
82
|
|
81
83
|
rubyforge_project: shared_tests
|
82
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.3.7
|
83
85
|
signing_key:
|
84
86
|
specification_version: 3
|
85
87
|
summary: Minimal DSL to write shared tests for Test::Unit
|