shoulda-let 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +20 -12
- data/Rakefile +1 -0
- data/Readme.md +54 -19
- data/gemfiles/shoulda2.gemfile +1 -0
- data/gemfiles/shoulda2.gemfile.lock +2 -0
- data/gemfiles/shoulda3.gemfile +1 -0
- data/gemfiles/shoulda3.gemfile.lock +2 -0
- data/lib/shoulda/let.rb +5 -19
- data/lib/shoulda/let/context_support.rb +30 -0
- data/lib/shoulda/let/test_case_support.rb +28 -0
- data/shoulda-let.gemspec +1 -1
- metadata +14 -12
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,34 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shoulda-let (0.0.
|
4
|
+
shoulda-let (0.0.4)
|
5
5
|
shoulda
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (3.2.
|
10
|
+
activesupport (3.2.9)
|
11
11
|
i18n (~> 0.6)
|
12
12
|
multi_json (~> 1.0)
|
13
|
-
appraisal (0.
|
13
|
+
appraisal (0.5.1)
|
14
14
|
bundler
|
15
15
|
rake
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
bourne (1.1.2)
|
17
|
+
mocha (= 0.10.5)
|
18
|
+
bump (0.3.7)
|
19
|
+
i18n (0.6.1)
|
20
|
+
metaclass (0.0.1)
|
21
|
+
mocha (0.10.5)
|
22
|
+
metaclass (~> 0.0.1)
|
23
|
+
multi_json (1.5.0)
|
24
|
+
rake (10.0.2)
|
25
|
+
shoulda (3.3.2)
|
26
|
+
shoulda-context (~> 1.0.1)
|
27
|
+
shoulda-matchers (~> 1.4.1)
|
28
|
+
shoulda-context (1.0.1)
|
29
|
+
shoulda-matchers (1.4.2)
|
24
30
|
activesupport (>= 3.0.0)
|
25
|
-
|
31
|
+
bourne (~> 1.1.2)
|
32
|
+
test-unit (2.5.3)
|
26
33
|
|
27
34
|
PLATFORMS
|
28
35
|
ruby
|
29
36
|
|
30
37
|
DEPENDENCIES
|
31
38
|
appraisal
|
39
|
+
bump
|
32
40
|
rake
|
33
41
|
shoulda-let!
|
34
42
|
test-unit (>= 2.5.1)
|
data/Rakefile
CHANGED
data/Readme.md
CHANGED
@@ -11,39 +11,74 @@ Install
|
|
11
11
|
Usage
|
12
12
|
=====
|
13
13
|
<!-- example -->
|
14
|
-
context "
|
15
|
-
|
16
|
-
|
14
|
+
context "let" do
|
15
|
+
let(:thing){ "a thing" }
|
16
|
+
|
17
|
+
should "make the result available via let" do
|
18
|
+
assert_equal 'a thing', let(:thing)
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'make the result available via an instance method' do
|
22
|
+
assert_equal 'a thing', thing
|
17
23
|
end
|
18
24
|
|
19
|
-
|
25
|
+
context "memoization" do
|
26
|
+
let(:thing) do
|
27
|
+
@invocations ||= 0
|
28
|
+
@invocations += 1
|
29
|
+
rand
|
30
|
+
end
|
31
|
+
|
32
|
+
should "be stable" do
|
33
|
+
first_value = thing
|
34
|
+
assert_equal first_value, thing
|
35
|
+
assert_equal first_value, let(:thing)
|
36
|
+
end
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
assert_equal "something", @result
|
38
|
+
should 'not reevaluate' do
|
39
|
+
thing; thing; thing
|
40
|
+
assert_equal 1, @invocations
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
28
|
-
context "with
|
29
|
-
let(:thing){
|
44
|
+
context "a child context with an overridden let" do
|
45
|
+
let(:thing) { 'child thing' }
|
30
46
|
|
31
|
-
should "
|
32
|
-
assert_equal
|
47
|
+
should "use the overridden value" do
|
48
|
+
assert_equal "child thing", thing
|
33
49
|
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'a child context with no overridden let' do
|
53
|
+
should 'use the parent value' do
|
54
|
+
assert_equal 'a thing', thing
|
55
|
+
end
|
56
|
+
end
|
34
57
|
|
35
|
-
|
36
|
-
|
58
|
+
context "let!" do
|
59
|
+
let!(:thing) do
|
60
|
+
@thing_instantiated = true
|
61
|
+
'anything'
|
37
62
|
end
|
38
63
|
|
39
|
-
should "
|
40
|
-
|
64
|
+
should "automatically be evaluated" do
|
65
|
+
assert @thing_instantiated
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'otherwise work like let' do
|
69
|
+
assert_equal 'anything', thing
|
41
70
|
end
|
42
71
|
end
|
43
72
|
|
44
|
-
context
|
45
|
-
|
46
|
-
|
73
|
+
context 'evaluation context' do
|
74
|
+
let(:thing) do
|
75
|
+
@let_evaluation_context = self
|
76
|
+
'a thing'
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'be the test case' do
|
80
|
+
thing
|
81
|
+
assert_equal self, @let_evaluation_context
|
47
82
|
end
|
48
83
|
end
|
49
84
|
end
|
data/gemfiles/shoulda2.gemfile
CHANGED
data/gemfiles/shoulda3.gemfile
CHANGED
data/lib/shoulda/let.rb
CHANGED
@@ -1,27 +1,13 @@
|
|
1
1
|
require "shoulda"
|
2
2
|
require "shoulda/context"
|
3
|
+
require 'shoulda/let/context_support'
|
4
|
+
require 'shoulda/let/test_case_support'
|
3
5
|
|
4
|
-
context_class = (Shoulda::
|
6
|
+
context_class = (defined?(Shoulda::Context::Context) ? Shoulda::Context::Context : Shoulda::Context)
|
5
7
|
context_class.class_eval do
|
6
|
-
|
7
|
-
# let(:foo){ "Foo" }
|
8
|
-
def let(name, &block)
|
9
|
-
@let ||= {}
|
10
|
-
if block
|
11
|
-
@let[name] = block
|
12
|
-
else
|
13
|
-
@let.fetch(name){ parent.let(name) }
|
14
|
-
end
|
15
|
-
end
|
8
|
+
include Shoulda::Let::ContextSupport
|
16
9
|
end
|
17
10
|
|
18
11
|
Test::Unit::TestCase.class_eval do
|
19
|
-
|
20
|
-
# assert_equal @result, let(:foo)
|
21
|
-
def let(name)
|
22
|
-
@let ||= {}
|
23
|
-
@let.fetch(name) do
|
24
|
-
@let[name] = instance_exec(&@shoulda_context.let(name))
|
25
|
-
end
|
26
|
-
end
|
12
|
+
include Shoulda::Let::TestCaseSupport
|
27
13
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Let
|
3
|
+
|
4
|
+
module ContextSupport
|
5
|
+
# setup method used outside of should blocks
|
6
|
+
# let(:foo){ "Foo" }
|
7
|
+
def let(name, &block)
|
8
|
+
name = name.to_sym
|
9
|
+
@let ||= {}
|
10
|
+
if block
|
11
|
+
@let[name] = block
|
12
|
+
else
|
13
|
+
@let.fetch(name){ parent.let(name) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def let!(name, &block)
|
18
|
+
let(name, &block)
|
19
|
+
setup { let(name) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def let_defined?(name)
|
23
|
+
name = name.to_sym
|
24
|
+
( @let && @let.has_key?(name) ) ||
|
25
|
+
( parent.respond_to?(:let_defined?) && parent.let_defined?(name) )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Let
|
3
|
+
|
4
|
+
module TestCaseSupport
|
5
|
+
# instance method used inside of should block
|
6
|
+
# assert_equal @result, let(:foo)
|
7
|
+
def let(name)
|
8
|
+
@let_cache ||= {}
|
9
|
+
@let_cache[name] ||= instance_exec(&@shoulda_context.let(name))
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *arguments, &block)
|
13
|
+
name = name.to_sym
|
14
|
+
if arguments.length == 0 && block.nil? && @shoulda_context.let_defined?(name)
|
15
|
+
let(name)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def respond_to?(name, *arguments, &block)
|
22
|
+
( @shoulda_context && @shoulda_context.let_defined?(name) ) || super
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/shoulda-let.gemspec
CHANGED
metadata
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-let
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Grosser
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
20
|
none: false
|
21
|
+
prerelease: false
|
22
|
+
name: shoulda
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - ! '>='
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
version: '0'
|
28
|
+
none: false
|
29
|
+
type: :runtime
|
30
30
|
description:
|
31
31
|
email: michael@grosser.it
|
32
32
|
executables: []
|
@@ -44,6 +44,8 @@ files:
|
|
44
44
|
- gemfiles/shoulda3.gemfile
|
45
45
|
- gemfiles/shoulda3.gemfile.lock
|
46
46
|
- lib/shoulda/let.rb
|
47
|
+
- lib/shoulda/let/context_support.rb
|
48
|
+
- lib/shoulda/let/test_case_support.rb
|
47
49
|
- shoulda-let.gemspec
|
48
50
|
- test/shoulda_let_test.rb
|
49
51
|
homepage: http://github.com/grosser/shoulda-let
|
@@ -54,23 +56,23 @@ rdoc_options: []
|
|
54
56
|
require_paths:
|
55
57
|
- lib
|
56
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
59
|
requirements:
|
59
60
|
- - ! '>='
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
63
|
segments:
|
63
64
|
- 0
|
64
|
-
hash:
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
hash: 4444769857253889543
|
66
66
|
none: false
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
68
|
requirements:
|
68
69
|
- - ! '>='
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
segments:
|
72
73
|
- 0
|
73
|
-
hash:
|
74
|
+
hash: 4444769857253889543
|
75
|
+
none: false
|
74
76
|
requirements: []
|
75
77
|
rubyforge_project:
|
76
78
|
rubygems_version: 1.8.24
|