giraffesoft-zebra 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/VERSION.yml +2 -2
- data/lib/zebra/shoulda.rb +42 -0
- data/lib/zebra.rb +35 -6
- data/test/{context_test.rb → context/context_test.rb} +5 -1
- data/test/{matchy_test.rb → else/matchy_test.rb} +2 -1
- data/test/shoulda/shoulda_test.rb +26 -0
- data/test/test_helper.rb +1 -0
- metadata +9 -12
data/README.rdoc
CHANGED
data/VERSION.yml
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Zebra
|
2
|
+
module Shoulda
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
attr_accessor :expects
|
6
|
+
|
7
|
+
alias_method :build_without_expects, :build
|
8
|
+
alias_method :build, :build_with_expects
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def expect(&block)
|
13
|
+
self.expects ||= []
|
14
|
+
self.expects << block
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_test_from_expect(&block)
|
18
|
+
test_name = expect_test_name(full_name, &block)
|
19
|
+
|
20
|
+
if test_unit_class.instance_methods.include?(test_name.to_s)
|
21
|
+
warn " * WARNING: '#{test_name}' is already defined"
|
22
|
+
end
|
23
|
+
|
24
|
+
context = self
|
25
|
+
test_unit_class.send(:define_method, test_name) do
|
26
|
+
begin
|
27
|
+
context.run_parent_setup_blocks(self)
|
28
|
+
context.run_current_setup_blocks(self)
|
29
|
+
block.bind(self).call
|
30
|
+
ensure
|
31
|
+
context.run_all_teardown_blocks(self)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_with_expects
|
37
|
+
(expects || []).each { |e| create_test_from_expect(&e) }
|
38
|
+
build_without_expects
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/lib/zebra.rb
CHANGED
@@ -1,18 +1,47 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require 'context'
|
3
2
|
require 'matchy'
|
4
3
|
require 'parse_tree'
|
5
4
|
require 'parse_tree_extensions'
|
6
5
|
require 'ruby2ruby'
|
6
|
+
require File.dirname(__FILE__) + '/zebra/shoulda'
|
7
7
|
|
8
8
|
module Zebra
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
class << self
|
10
|
+
def shoulda?
|
11
|
+
defined?(Thoughtbot)
|
12
|
+
end
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
def expect(&block)
|
16
|
+
Zebra.shoulda? ? expect_shoulda(&block) : expect_context(&block)
|
15
17
|
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def expect_shoulda(&block)
|
21
|
+
Thoughtbot::Shoulda::Context.send(:include, Zebra::Shoulda) unless Thoughtbot::Shoulda::Context.include?(Zebra::Shoulda)
|
22
|
+
|
23
|
+
if Thoughtbot::Shoulda.current_context
|
24
|
+
Thoughtbot::Shoulda.current_context.expect(&block)
|
25
|
+
else
|
26
|
+
context_name = self.name.gsub(/Test/, "")
|
27
|
+
context = Thoughtbot::Shoulda::Context.new(context_name, self) do
|
28
|
+
expect(&block)
|
29
|
+
end
|
30
|
+
context.build
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def expect_context(&block)
|
35
|
+
define_method(expect_test_name(context_name, &block), &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def expect_test_name(context_name, &block)
|
39
|
+
block_translation = block.to_ruby.gsub /proc \{ (.+?) \}/, '\1'
|
40
|
+
test_name = ["test:", context_name, "expect", block_translation]
|
41
|
+
test_name.reject! { |s| s == "" }
|
42
|
+
|
43
|
+
test_name.join(' ')
|
44
|
+
end
|
16
45
|
end
|
17
46
|
|
18
47
|
Test::Unit::TestCase.send(:extend, Zebra)
|
@@ -1,7 +1,11 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
require 'context'
|
3
3
|
|
4
4
|
class ContextTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Zebra.stubs(:shoulda?).returns(false)
|
7
|
+
end
|
8
|
+
|
5
9
|
it "should create a test" do
|
6
10
|
self.class.expect { 2.to == 1 }
|
7
11
|
assert self.respond_to?("test: expect (2.to == 1)")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'shoulda'
|
3
|
+
|
4
|
+
class ShouldaTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Zebra.stubs(:shoulda?).returns(true)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "create a test" do
|
10
|
+
self.class.expect { 2.to == 1 }
|
11
|
+
assert self.respond_to?("test: Shoulda expect (2.to == 1)"), self.class.instance_methods.grep(/test/).inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
context "in a context" do
|
15
|
+
expect { true }
|
16
|
+
should "grab the name of the context" do
|
17
|
+
assert self.respond_to?("test: in a context expect true"), self.class.instance_methods.grep(/test/).inspect
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "A context with no expects" do
|
22
|
+
should "not raise any exceptions" do
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giraffesoft-zebra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Golick
|
@@ -12,15 +12,6 @@ cert_chain: []
|
|
12
12
|
date: 2009-01-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: jeremymcanally-context
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.5.2
|
23
|
-
version:
|
24
15
|
- !ruby/object:Gem::Dependency
|
25
16
|
name: jeremymcanally-matchy
|
26
17
|
version_requirement:
|
@@ -59,9 +50,15 @@ extra_rdoc_files: []
|
|
59
50
|
files:
|
60
51
|
- README.rdoc
|
61
52
|
- VERSION.yml
|
53
|
+
- lib/zebra
|
54
|
+
- lib/zebra/shoulda.rb
|
62
55
|
- lib/zebra.rb
|
63
|
-
- test/
|
64
|
-
- test/
|
56
|
+
- test/context
|
57
|
+
- test/context/context_test.rb
|
58
|
+
- test/else
|
59
|
+
- test/else/matchy_test.rb
|
60
|
+
- test/shoulda
|
61
|
+
- test/shoulda/shoulda_test.rb
|
65
62
|
- test/test_helper.rb
|
66
63
|
has_rdoc: false
|
67
64
|
homepage: http://github.com/giraffesoft/zebra
|