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 CHANGED
@@ -1,6 +1,7 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
+ gem "bump"
4
5
  gem "rake"
5
6
  gem "test-unit", ">=2.5.1"
6
7
  gem "appraisal"
@@ -1,34 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shoulda-let (0.0.3)
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.8)
10
+ activesupport (3.2.9)
11
11
  i18n (~> 0.6)
12
12
  multi_json (~> 1.0)
13
- appraisal (0.4.1)
13
+ appraisal (0.5.1)
14
14
  bundler
15
15
  rake
16
- i18n (0.6.0)
17
- multi_json (1.3.6)
18
- rake (0.9.2.2)
19
- shoulda (3.1.1)
20
- shoulda-context (~> 1.0)
21
- shoulda-matchers (~> 1.2)
22
- shoulda-context (1.0.0)
23
- shoulda-matchers (1.2.0)
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
- test-unit (2.5.1)
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
@@ -1,5 +1,6 @@
1
1
  require 'appraisal'
2
2
  require 'bundler/gem_tasks'
3
+ require 'bump/tasks'
3
4
 
4
5
  task :test do
5
6
  sh "ruby test/shoulda_let_test.rb"
data/Readme.md CHANGED
@@ -11,39 +11,74 @@ Install
11
11
  Usage
12
12
  =====
13
13
  <!-- example -->
14
- context "foo" do
15
- setup do
16
- @result = let(:thing)
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
- let(:thing){ "parent" }
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
- context "with something" do
22
- let(:thing){ "something" }
23
- should "be something" do
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 cache" do
29
- let(:thing){ rand }
44
+ context "a child context with an overridden let" do
45
+ let(:thing) { 'child thing' }
30
46
 
31
- should "be stable" do
32
- assert_equal @result, let(:thing)
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
- should "be different" do
36
- assert_not_equal $last_thing, let(:thing)
58
+ context "let!" do
59
+ let!(:thing) do
60
+ @thing_instantiated = true
61
+ 'anything'
37
62
  end
38
63
 
39
- should "prepare for be different" do
40
- $last_thing = let(:thing)
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 "with parent" do
45
- should "be parent" do
46
- assert_equal "parent", @result
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  source :rubygems
4
4
 
5
+ gem "bump"
5
6
  gem "rake"
6
7
  gem "test-unit", ">=2.5.1"
7
8
  gem "appraisal"
@@ -10,6 +10,7 @@ GEM
10
10
  appraisal (0.4.1)
11
11
  bundler
12
12
  rake
13
+ bump (0.3.7)
13
14
  rake (0.9.2.2)
14
15
  shoulda (2.11.3)
15
16
  test-unit (2.5.1)
@@ -19,6 +20,7 @@ PLATFORMS
19
20
 
20
21
  DEPENDENCIES
21
22
  appraisal
23
+ bump
22
24
  rake
23
25
  shoulda (~> 2.11)
24
26
  shoulda-let!
@@ -2,6 +2,7 @@
2
2
 
3
3
  source :rubygems
4
4
 
5
+ gem "bump"
5
6
  gem "rake"
6
7
  gem "test-unit", ">=2.5.1"
7
8
  gem "appraisal"
@@ -13,6 +13,7 @@ GEM
13
13
  appraisal (0.4.1)
14
14
  bundler
15
15
  rake
16
+ bump (0.3.7)
16
17
  i18n (0.6.0)
17
18
  multi_json (1.3.6)
18
19
  rake (0.9.2.2)
@@ -29,6 +30,7 @@ PLATFORMS
29
30
 
30
31
  DEPENDENCIES
31
32
  appraisal
33
+ bump
32
34
  rake
33
35
  shoulda (~> 3.1)
34
36
  shoulda-let!
@@ -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::VERSION >= "3.0.0" ? Shoulda::Context::Context : Shoulda::Context)
6
+ context_class = (defined?(Shoulda::Context::Context) ? Shoulda::Context::Context : Shoulda::Context)
5
7
  context_class.class_eval do
6
- # setup method used outside of should blocks
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
- # instance method used inside of should block
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
@@ -1,6 +1,6 @@
1
1
  name = "shoulda-let"
2
2
 
3
- Gem::Specification.new name, "0.0.3" do |s|
3
+ Gem::Specification.new name, "0.0.4" do |s|
4
4
  s.summary = "A simple let for shoulda"
5
5
  s.authors = ["Michael Grosser"]
6
6
  s.email = "michael@grosser.it"
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-08-24 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: shoulda
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: -3119661042567922531
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: -3119661042567922531
74
+ hash: 4444769857253889543
75
+ none: false
74
76
  requirements: []
75
77
  rubyforge_project:
76
78
  rubygems_version: 1.8.24