shared_tests 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.verbose = true
11
+ end
data/Readme.md CHANGED
@@ -1,84 +1,88 @@
1
1
  # Shared tests
2
2
 
3
- Shared tests is a minimal DSL for Test::Unit that let's you assert the behavior shared by your objects
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
- ## Installation
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
- module ProgrammingMotherfucker
16
- def what_am_i?
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
- ```ruby
25
- class Hacker
26
- include ProgrammingMotherfucker
27
- end
11
+ def setup
12
+ @subject = "I have length"
13
+ end
28
14
 
29
- class SysAdmin
30
- include ProgrammingMotherfucker
15
+ assert_tests :of => :length
31
16
  end
32
- ```
33
17
 
34
- To test it first the little pattern: declare the shared behavior test examples inside a module,
35
- the trick here is to add the `Tests` word as the end of the module name.
18
+ class ArrayTest < Test::Unit::TestCase
19
+ include SharedTests
36
20
 
37
- ```ruby
38
- module ProgrammingMotherfuckerTests
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
- Now you can assert that a hacker is a programming motherfucker,
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
- class HackerTest < Test::Unit::TestCase
50
- include SharedTests # include the shared_tests support
32
+ module LengthTests
33
+ def test_length_is_not_zero
34
+ assert @subject.length > 0
35
+ end
51
36
 
52
- assert_shared_tests :of => :programming_motherfucker do
53
- # this is the setup of the shared tests
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
- and sysadmins also,
43
+ It's all about readability, the same without using the assertion would be
60
44
 
61
45
  ```ruby
62
- class SysAdminTest < Test::Unit::TestCase
46
+ class StringTest < Test::Unit::TestCase
63
47
  include SharedTests
64
48
 
65
- # or you can use the shorter version
66
- assert_tests :of => :programming_motherfucker do
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
- * allow to use @variables names in the setups different that those inside ProgrammingMotherfuckerTests
76
- * Travis integration
77
- * collect my programming motherfucker tshirt :-)
77
+ * make it work with shoulda?
78
+
79
+ ## Build status
80
+
81
+ [![Build Status](https://secure.travis-ci.org/joahking/shared_tests.png)](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, InstanceMethods
6
+ base.send :extend, ClassMethods
7
7
  end
8
8
 
9
- module InstanceMethods
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
 
@@ -1,3 +1,3 @@
1
1
  module SharedTests
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,45 +1,32 @@
1
1
  require 'test/unit'
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../lib/shared_tests')
3
3
 
4
- # shared behavior we want to test
5
- module ProgrammingMotherfucker
6
- def what_am_i?
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
- # so are sys admin instances
17
- class SysAdmin
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
- # the hacker tests
29
- class HackerTest < Test::Unit::TestCase
14
+ class StringTest < Test::Unit::TestCase
30
15
  include SharedTests
31
16
 
32
- assert_shared_tests :of => :programming_motherfucker do
33
- @me = Hacker.new
17
+ def setup
18
+ @subject = "I have length"
34
19
  end
20
+
21
+ assert_tests :of => :length
35
22
  end
36
23
 
37
- # the sysadmin tests
38
- class SysAdminUsesShortHandTest < Test::Unit::TestCase
24
+ class ArrayTest < Test::Unit::TestCase
39
25
  include SharedTests
40
26
 
41
- # using short hand
42
- assert_tests :of => :programming_motherfucker do
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: 27
5
- prerelease:
4
+ hash: 25
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
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-22 00:00:00 Z
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.8.11
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