shared_tests 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md ADDED
@@ -0,0 +1,85 @@
1
+ # Shared tests
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.
5
+
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.
13
+
14
+ ```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.
23
+
24
+ ```ruby
25
+ class Hacker
26
+ include ProgrammingMotherfucker
27
+ end
28
+
29
+ class SysAdmin
30
+ include ProgrammingMotherfucker
31
+ end
32
+ ```
33
+
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.
36
+
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"
42
+ end
43
+ end
44
+ ```
45
+
46
+ Now you can assert that a hacker is a programming motherfucker,
47
+
48
+ ```ruby
49
+ class HackerTest < Test::Unit::TestCase
50
+ include SharedTests # include the shared_tests support
51
+
52
+ assert_shared_tests :of => :programming_motherfucker do
53
+ # this is the setup of the shared tests
54
+ @me = Hacker.new
55
+ end
56
+ end
57
+ ```
58
+
59
+ and sysadmins also,
60
+
61
+ ```ruby
62
+ class SysAdminTest < Test::Unit::TestCase
63
+ include SharedTests
64
+
65
+ # or you can use the shorter version
66
+ assert_tests :of => :programming_motherfucker do
67
+ @me = SysAdmin.new
68
+ end
69
+ end
70
+ ```
71
+
72
+ ## TODO
73
+
74
+ * 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 :-)
78
+
79
+ ## Thanks
80
+
81
+ * [Jorge Días](https://github.com/diasjorge) for useful tips.
82
+
83
+ ## License
84
+
85
+ Do something good for mankind license. A good will action would be awesome, a happy thought will do.
data/lib/shared_tests.rb CHANGED
@@ -7,16 +7,16 @@ module SharedTests
7
7
  end
8
8
 
9
9
  module InstanceMethods
10
-
11
10
  def assert_shared_tests(options = {}, &block)
12
11
  shared_test = options.delete(:of)
13
12
  include "#{shared_test.to_s.camelize}Tests".constantize
14
13
 
15
14
  define_method(:setup) do
16
15
  super()
17
- instance_eval(&block)
16
+ instance_eval &block
18
17
  end
19
18
  end
19
+ alias_method :assert_tests, :assert_shared_tests
20
20
 
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module SharedTests
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/shared_tests')
3
3
 
4
4
  # shared behavior we want to test
5
5
  module ProgrammingMotherfucker
6
- def who_am_i?
6
+ def what_am_i?
7
7
  "a programming motherfucker"
8
8
  end
9
9
  end
@@ -13,14 +13,19 @@ class Hacker
13
13
  include ProgrammingMotherfucker
14
14
  end
15
15
 
16
+ # so are sys admin instances
17
+ class SysAdmin
18
+ include ProgrammingMotherfucker
19
+ end
20
+
16
21
  # declaring the shared behavior test examples
17
22
  module ProgrammingMotherfuckerTests
18
23
  def test_is_a_programming_motherfucker?
19
- assert @me.who_am_i? == "a programming motherfucker"
24
+ assert @me.what_am_i? == "a programming motherfucker"
20
25
  end
21
26
  end
22
27
 
23
- # and the hacker tests
28
+ # the hacker tests
24
29
  class HackerTest < Test::Unit::TestCase
25
30
  include SharedTests
26
31
 
@@ -28,3 +33,13 @@ class HackerTest < Test::Unit::TestCase
28
33
  @me = Hacker.new
29
34
  end
30
35
  end
36
+
37
+ # the sysadmin tests
38
+ class SysAdminUsesShortHandTest < Test::Unit::TestCase
39
+ include SharedTests
40
+
41
+ # using short hand
42
+ assert_tests :of => :programming_motherfucker do
43
+ @me = SysAdmin.new
44
+ end
45
+ 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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joaquin Rivera Padron
@@ -45,6 +45,7 @@ files:
45
45
  - Gemfile
46
46
  - Gemfile.lock
47
47
  - Rakefile
48
+ - Readme.md
48
49
  - lib/shared_tests.rb
49
50
  - lib/shared_tests/version.rb
50
51
  - shared_tests.gemspec