jeremymcanally-context 0.0.5 → 0.0.6

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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "context"
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
4
4
  s.date = "2008-10-03"
5
5
  s.summary = "Contexts and DSL sugar for your tests"
6
6
  s.email = "jeremy@entp.com"
@@ -50,8 +50,7 @@ class Test::Unit::TestCase
50
50
  cls.class_eval(&block)
51
51
  (self.context_list ||= []) << cls
52
52
 
53
- # TODO: Find a better way to uniquely identify classes
54
- const_set("Test#{name.to_class_name}#{cls.object_id}", cls)
53
+ const_set("Test#{name.to_class_name}#{cls.object_id.abs}", cls)
55
54
  cls
56
55
  end
57
56
 
@@ -22,7 +22,7 @@ class Test::Unit::TestCase
22
22
  send("after_#{period}_callbacks") << block
23
23
  end
24
24
 
25
- def gather_callbacks(callback_type, period)
25
+ def gather_callbacks(callback_type, period) # :nodoc:
26
26
  callbacks = superclass.respond_to?(:gather_callbacks) ? superclass.gather_callbacks(callback_type, period) : []
27
27
  callbacks.push(*send("#{callback_type}_#{period}_callbacks"))
28
28
  end
@@ -33,7 +33,7 @@ class Test::Unit::TestCase
33
33
  self.after_each_callbacks = []
34
34
  self.after_all_callbacks = []
35
35
 
36
- def self.inherited(child)
36
+ def self.inherited(child) # :nodoc:
37
37
  super
38
38
  child.before_all_callbacks = []
39
39
  child.before_each_callbacks = []
@@ -51,11 +51,11 @@ class Test::Unit::TestCase
51
51
  end
52
52
  end
53
53
 
54
- def run_each_callbacks(callback_type)
54
+ def run_each_callbacks(callback_type) # :nodoc:
55
55
  self.class.gather_callbacks(callback_type, :each).each { |c| instance_eval(&c) }
56
56
  end
57
57
 
58
- def run_all_callbacks(callback_type)
58
+ def run_all_callbacks(callback_type) # :nodoc:
59
59
  previous_ivars = instance_variables
60
60
  self.class.gather_callbacks(callback_type, :all).each { |c| instance_eval(&c) }
61
61
  (instance_variables - previous_ivars).inject({}) do |hash, ivar|
@@ -63,7 +63,7 @@ class Test::Unit::TestCase
63
63
  end
64
64
  end
65
65
 
66
- def set_values_from_callbacks(values)
66
+ def set_values_from_callbacks(values) # :nodoc:
67
67
  values.each do |name, value|
68
68
  instance_variable_set name, value
69
69
  end
@@ -1,25 +1,51 @@
1
- class SharedContext < Module
2
- def self.create_from_behavior(beh)
3
- mod = self.new
4
- mod.behavior = beh
5
- mod
6
- end
7
-
8
- def behavior=(beh)
9
- @behavior = beh
10
- end
1
+ module Context
2
+ class SharedBehavior < Module
3
+ def self.create_from_behavior(beh) # :nodoc:
4
+ mod = self.new
5
+ mod._behavior = beh
6
+
7
+ mod
8
+ end
11
9
 
12
- def behavior
13
- @behavior
14
- end
10
+ def _behavior=(beh) # :nodoc:
11
+ @_behavior = beh
12
+ end
15
13
 
16
- def included(arg)
17
- @behavior.call
14
+ def included(arg) # :nodoc:
15
+ @_behavior.call
16
+ end
18
17
  end
19
18
  end
20
19
 
21
20
  class Test::Unit::TestCase
22
21
  class << self
22
+ # Share behavior among different contexts. This creates a module (actually, a Module subclass)
23
+ # that is included using the +use+ method (or one of its aliases) provided by context or +include+
24
+ # if you know the module's constant name.
25
+ #
26
+ # ==== Examples
27
+ #
28
+ # shared "other things" do
29
+ # it "should do things but not some things" do
30
+ # # behavior is fun
31
+ # end
32
+ # end
33
+ #
34
+ # use "other things"
35
+ # # or...
36
+ # it_should_behave_like "other things"
37
+ #
38
+ # shared :client do
39
+ # it "should be a client to our server" do
40
+ # # TODO: client behavior here
41
+ # end
42
+ # end
43
+ #
44
+ # use :client
45
+ # # or...
46
+ # uses "client"
47
+ # behaves_like "client"
48
+ #
23
49
  def shared(name, &block)
24
50
  case name.class.name
25
51
  when "String"
@@ -30,14 +56,33 @@ class Test::Unit::TestCase
30
56
  raise ArgumentError, "Provide a String or Symbol as the name of the shared behavior group"
31
57
  end
32
58
 
33
- Object.const_set(name, SharedContext.create_from_behavior(block))
59
+ Object.const_set(name, Context::SharedBehavior.create_from_behavior(block))
34
60
  end
35
61
 
36
62
  %w(shared_behavior share_as share_behavior_as shared_examples_for).each {|m| alias_method m, :shared}
37
63
 
64
+ # Pull in behavior shared by +shared+ or a module.
65
+ #
66
+ # ==== Examples
67
+ #
68
+ # shared "other things" do
69
+ # it "should do things but not some things" do
70
+ # # behavior is fun
71
+ # end
72
+ # end
73
+ #
74
+ # use "other things"
75
+ # # or...
76
+ # it_should_behave_like "other things"
77
+ #
78
+ # module Things
79
+ # end
80
+ #
81
+ # uses Things
82
+ #
38
83
  def use(shared_name)
39
84
  case shared_name.class.name
40
- when "SharedContext", "Module"
85
+ when "Context::SharedBehavior", "Module"
41
86
  include shared_name
42
87
  when "String"
43
88
  include Object.const_get(shared_name.to_module_name)
@@ -24,7 +24,7 @@ module Test
24
24
  class TestSuite
25
25
  # Runs the tests and/or suites contained in this
26
26
  # TestSuite.
27
- def run(result, &progress_block)
27
+ def run(result, &progress_block) # :nodoc:
28
28
  yield(STARTED, name)
29
29
  ivars_from_callback = @tests.first.run_all_callbacks(:before) if @tests.first.is_a?(Test::Unit::TestCase)
30
30
  @tests.each do |test|
@@ -2,7 +2,7 @@ module Context
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremymcanally-context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy McAnally