chanko 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30b75ddfc1e9fe43d6d3b754e7fbf52d335cc3fc
4
- data.tar.gz: 95f8aff4181c18e35e9c9bab4764c8c965e10fec
3
+ metadata.gz: f325906ba94cd59313a68d2cba3be3bb6d3b05f9
4
+ data.tar.gz: 5a7e857db28ef637d4fed3c77bd3c6976885fcc7
5
5
  SHA512:
6
- metadata.gz: 475502c0c6e2795a09ec61ec99fb42ebdae1d34c63b35e49304a943c4f6b7806c6b688115662255ef155947e417b7ba62253c7ad17f741d11d122ba5e36b6433
7
- data.tar.gz: 4984aabddb178deea973816105c6b3a590d2dc2b5901a1ec61c6a52e86f7b4797a5582a019437cc3b25069167094db4d9cf90cd8373b616708cf56d5ccfdda4e
6
+ metadata.gz: f456c90d96c0ad8002028cf1c8d5402878133c330ec59917a75bdffb5ddece6937ce412337270cc8e455331e8160833b77a8ac467f21cb84d5194a0052b6edd6
7
+ data.tar.gz: 5180320d9015bdcca75c76ba35c99ed2177e5f54da759e25680da76745fe17f160faa9304225a3f9891f9b5ab7998cc512a9c174a2df3226926cb392819bbbde
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.0
4
+ - 2.1
5
+ - 2.2
5
6
  branches:
6
7
  only:
7
8
  - master
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.7
2
+ * Fix run_default again. 2.0.6 still has run_default bug. Use unstack block instad of depth counting.
3
+
4
+
1
5
  ## 2.0.6
2
6
  * Fix stack control of run_default.
3
7
 
data/Gemfile CHANGED
@@ -3,24 +3,9 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :development, :test, :production do
6
- gem "jquery-rails"
7
6
  gem "quiet_assets"
8
- gem "rails", ">= 4.0.0"
9
- gem "slim"
10
- gem "sqlite3"
11
- end
12
-
13
- group :test do
14
- gem "rspec-rails", "2.14.0"
15
7
  end
16
8
 
17
9
  group :development, :test do
18
10
  gem "pry-rails"
19
- gem "thin"
20
- end
21
-
22
- group :assets do
23
- gem "sass-rails"
24
- gem "coffee-rails"
25
- gem "uglifier"
26
11
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Chanko [![Build Status](https://travis-ci.org/cookpad/chanko.png)](https://travis-ci.org/cookpad/chanko) [![Code Climate](https://codeclimate.com/github/cookpad/chanko.png)](https://codeclimate.com/github/cookpad/chanko) [![Coverage Status](https://coveralls.io/repos/cookpad/chanko/badge.png?branch=master)](https://coveralls.io/r/cookpad/chanko)
1
+ # Chanko [![Build Status](https://travis-ci.org/cookpad/chanko.svg?branch=master)](https://travis-ci.org/cookpad/chanko) [![Code Climate](https://codeclimate.com/github/cookpad/chanko/badges/gpa.svg)](https://codeclimate.com/github/cookpad/chanko) [![Coverage Status](https://coveralls.io/repos/cookpad/chanko/badge.svg?branch=master)](https://coveralls.io/r/cookpad/chanko?branch=master)
2
2
 
3
3
  http://cookpad.github.io/chanko/
4
4
 
data/chanko.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency "coveralls"
22
22
  gem.add_development_dependency "jquery-rails"
23
23
  gem.add_development_dependency "pry"
24
- gem.add_development_dependency "rspec-rails", "2.12.2"
24
+ gem.add_development_dependency "rspec-rails", ">= 3.0.0"
25
25
  gem.add_development_dependency "sass-rails", ">= 3.0.10"
26
26
  gem.add_development_dependency "simplecov"
27
27
  gem.add_development_dependency "slim"
@@ -40,18 +40,6 @@ module Chanko
40
40
  end
41
41
  end
42
42
 
43
- def __current_run_default_depth
44
- @__run_default_depth ||= 0
45
- end
46
-
47
- def __increment_run_default_depth
48
- @__run_default_depth = __current_run_default_depth + 1
49
- end
50
-
51
- def __decrement_run_default_depth
52
- @__run_default_depth = __current_run_default_depth - 1
53
- end
54
-
55
43
  def __find_unit_local(method_name)
56
44
  __current_unit_locals.has_key?(method_name)
57
45
  end
@@ -61,7 +49,7 @@ module Chanko
61
49
  end
62
50
 
63
51
  def __current_unit_locals
64
- __unit_locals_stack[-1 - __current_run_default_depth] || {}
52
+ __unit_locals_stack.last || {}
65
53
  end
66
54
 
67
55
  def __unit_locals_stack
@@ -85,7 +73,7 @@ module Chanko
85
73
  end
86
74
 
87
75
  def __default_block
88
- __defaults_stack[-1 - __current_run_default_depth]
76
+ __defaults_stack.last
89
77
  end
90
78
 
91
79
  def __has_default_block?
@@ -95,14 +83,15 @@ module Chanko
95
83
  def __invoke_default_block
96
84
  current_default_block = __default_block
97
85
  begin
98
- __increment_run_default_depth
99
- if view?
100
- capture(&current_default_block)
101
- else
102
- instance_exec(&current_default_block)
86
+ __without_default_stack do
87
+ __without_locals_stack do
88
+ if view?
89
+ capture(&current_default_block)
90
+ else
91
+ instance_exec(&current_default_block)
92
+ end
93
+ end
103
94
  end
104
- ensure
105
- __decrement_run_default_depth
106
95
  end
107
96
  end
108
97
 
@@ -119,5 +108,19 @@ module Chanko
119
108
  ensure
120
109
  __unit_locals_stack.pop
121
110
  end
111
+
112
+ def __without_default_stack
113
+ default = __defaults_stack.pop
114
+ yield
115
+ ensure
116
+ __defaults_stack << default
117
+ end
118
+
119
+ def __without_locals_stack
120
+ locals = __unit_locals_stack.pop
121
+ yield
122
+ ensure
123
+ __unit_locals_stack << locals
124
+ end
122
125
  end
123
126
  end
@@ -1,3 +1,3 @@
1
1
  module Chanko
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.7"
3
3
  end
@@ -22,21 +22,21 @@ module Chanko
22
22
  end
23
23
 
24
24
  it "defines an action to invoke unit function" do
25
- controller.test.should == "test"
25
+ expect(controller.test).to eq("test")
26
26
  end
27
27
 
28
28
  it "defines 2 actions at one line" do
29
- controller.foo.should == "foo"
30
- controller.bar.should == "bar"
29
+ expect(controller.foo).to eq("foo")
30
+ expect(controller.bar).to eq("bar")
31
31
  end
32
32
 
33
33
  it "is aliased with `ext_action`" do
34
- controller.alias.should == "alias"
34
+ expect(controller.alias).to eq("alias")
35
35
  end
36
36
 
37
37
  context "when invoke is fallen back" do
38
38
  it "halts with 400 status code" do
39
- controller.error.should == "Bad Request 400"
39
+ expect(controller.error).to eq("Bad Request 400")
40
40
  end
41
41
  end
42
42
  end
@@ -12,7 +12,7 @@ module Chanko
12
12
  context "with option arguments" do
13
13
  it "prints warning message on standard error output" do
14
14
  ActiveIf.new(foo: "bar")
15
- $stderr.string.should =~ /\Aoptions in ActiveIf#new are deprecated and are never used at #{__FILE__}/
15
+ expect($stderr.string).to match(/\Aoptions in ActiveIf#new are deprecated and are never used at #{__FILE__}/)
16
16
  end
17
17
  end
18
18
  end
@@ -20,7 +20,7 @@ module Chanko
20
20
  describe "#options" do
21
21
  it "prints warning message on standard error output" do
22
22
  ActiveIf.new.options
23
- $stderr.string.should =~ /\AActiveIf#options is deprecated and is never used at #{__FILE__}/
23
+ expect($stderr.string).to match(/\AActiveIf#options is deprecated and is never used at #{__FILE__}/)
24
24
  end
25
25
  end
26
26
  end
@@ -20,7 +20,7 @@ module Chanko
20
20
  end
21
21
 
22
22
  it "raises up error without any logging" do
23
- Logger.should_not_receive(:debug)
23
+ expect(Logger).not_to receive(:debug)
24
24
  expect { described_class.handle(error, insensitive_unit) }.to raise_error
25
25
  end
26
26
  end
@@ -40,19 +40,19 @@ module Chanko
40
40
 
41
41
  describe ".invoke" do
42
42
  it "invokes block with given context and stacked unit" do
43
- described_class.new(unit, :label) { current_unit }.invoke(context, options).should == unit
43
+ expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
44
44
  end
45
45
 
46
46
  context "when context is a view" do
47
47
  it "invokes with unit's view path" do
48
- described_class.new(unit, :label) { path }.invoke(context, options).should == unit.view_path
48
+ expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
49
49
  end
50
50
  end
51
51
 
52
52
  context "when context does not have view_paths" do
53
53
  it "invokes successfully" do
54
- described_class.new(unit, :label) { "test" }.
55
- invoke(context_without_view_paths, options).should == "test"
54
+ expect(described_class.new(unit, :label) { "test" }.
55
+ invoke(context_without_view_paths, options)).to eq("test")
56
56
  end
57
57
  end
58
58
  end
@@ -19,7 +19,7 @@ module Chanko
19
19
  "test"
20
20
  end
21
21
  end
22
- view.__example_unit_test.should == "test"
22
+ expect(view.__example_unit_test).to eq("test")
23
23
  end
24
24
  end
25
25
  end
@@ -20,25 +20,25 @@ module Chanko
20
20
 
21
21
  describe "#invoke" do
22
22
  it "invokes in the same context with receiver" do
23
- view.invoke(:example_unit, :self, :type => :plain).should == view
23
+ expect(view.invoke(:example_unit, :self, :type => :plain)).to eq(view)
24
24
  end
25
25
 
26
26
  it "invokes with locals option" do
27
- view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain).
28
- should == "value"
27
+ expect(view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain)).
28
+ to eq("value")
29
29
  end
30
30
 
31
31
  it "invokes with falsy locals" do
32
- view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain).
33
- should == true
32
+ expect(view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain)).
33
+ to eq(true)
34
34
  end
35
35
 
36
36
  it "invokes with shared method" do
37
- view.invoke(:example_unit, :shared, :type => :plain).should == "shared args"
37
+ expect(view.invoke(:example_unit, :shared, :type => :plain)).to eq("shared args")
38
38
  end
39
39
 
40
40
  it "invokes with helper method in view context" do
41
- view.invoke(:example_unit, :helper, :type => :plain).should == "helper"
41
+ expect(view.invoke(:example_unit, :helper, :type => :plain)).to eq("helper")
42
42
  end
43
43
 
44
44
  context 'when unit is referred from unit function' do
@@ -49,27 +49,29 @@ module Chanko
49
49
 
50
50
  context "when invoked in view" do
51
51
  it "invokes with partial view" do
52
- view.invoke(:example_unit, :render, :type => :plain).should == "test\n"
52
+ expect(view.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
53
53
  end
54
54
  end
55
55
 
56
56
  context "when invoked in controller" do
57
57
  it "invokes with unit views path" do
58
- controller.invoke(:example_unit, :render, :type => :plain).should == "test\n"
58
+ expect(controller.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
59
59
  end
60
60
  end
61
61
 
62
62
  context "when short-hand style args is passed" do
63
63
  it "recognizes args as locals option" do
64
- view.invoke(:example_unit, :locals, :key => "value").should ==
64
+ expect(view.invoke(:example_unit, :locals, :key => "value")).to eq(
65
65
  '<div class="unit unit__example_unit unit__example_unit__locals">value</div>'
66
+ )
66
67
  end
67
68
  end
68
69
 
69
70
  context "when type is not specified" do
70
71
  it "invokes and returns result surrounded by div" do
71
- view.invoke(:example_unit, :test).should ==
72
+ expect(view.invoke(:example_unit, :test)).to eq(
72
73
  '<div class="unit unit__example_unit unit__example_unit__test">test</div>'
74
+ )
73
75
  end
74
76
  end
75
77
 
@@ -79,39 +81,41 @@ module Chanko
79
81
  end
80
82
 
81
83
  it "invokes and returns result surrounded by div" do
82
- view.invoke(:example_unit, :test).should ==
84
+ expect(view.invoke(:example_unit, :test)).to eq(
83
85
  '<div class="extension ext_example_unit ext_example_unit-test">test</div>'
86
+ )
84
87
  end
85
88
  end
86
89
 
87
90
  context "when type is :plain" do
88
91
  it "does not surround result with html element" do
89
- view.invoke(:example_unit, :test, :type => :plain).should == "test"
92
+ expect(view.invoke(:example_unit, :test, :type => :plain)).to eq("test")
90
93
  end
91
94
  end
92
95
 
93
96
  context "when the result is blank" do
94
97
  it "does not surround result with html element" do
95
- view.invoke(:example_unit, :blank).should == " "
98
+ expect(view.invoke(:example_unit, :blank)).to eq(" ")
96
99
  end
97
100
  end
98
101
 
99
102
  context "when type is :inline" do
100
103
  it "invokes and returns result surrounded by span" do
101
- view.invoke(:example_unit, :test, :type => :inline).should ==
104
+ expect(view.invoke(:example_unit, :test, :type => :inline)).to eq(
102
105
  '<span class="unit unit__example_unit unit__example_unit__test">test</span>'
106
+ )
103
107
  end
104
108
  end
105
109
 
106
110
  context "when context is not a view" do
107
111
  it "does not surround result with html tag" do
108
- controller.invoke(:example_unit, :test).should == "test"
112
+ expect(controller.invoke(:example_unit, :test)).to eq("test")
109
113
  end
110
114
  end
111
115
 
112
116
  context "when run_default is called in function" do
113
117
  it "invokes given block as a fallback" do
114
- controller.invoke(:example_unit, :default) { "default" }.should == "default"
118
+ expect(controller.invoke(:example_unit, :default) { "default" }).to eq("default")
115
119
  end
116
120
  end
117
121
 
@@ -120,34 +124,41 @@ module Chanko
120
124
  Chanko::Loader.load("sensitive_unit")
121
125
  expect(SensitiveUnit).to receive(:ping).once
122
126
 
123
- controller.invoke(:sensitive_unit, :outer_default) do
127
+ expect(controller.invoke(:sensitive_unit, :outer_default) do
124
128
  "default"
125
- end.should eq "default"
129
+ end).to eq "default"
126
130
  end
127
131
 
128
132
  it 'use both locals' do
129
- controller.invoke(:example_unit, :nesting_locals_outer, :locals => { :outer_one => "outer_one", :outer_two => "outer_two", :outer_three => "outer_three"}) do
133
+ expect(controller.invoke(:example_unit, :nesting_locals_outer, :locals => { :outer_one => "outer_one", :outer_two => "outer_two", :outer_three => "outer_three"}) do
130
134
  "default"
131
- end.should eq "outer_one.inner_one.outer_two.default.inner_two.outer_three"
135
+ end).to eq "outer_one.inner_one.outer_two.default.inner_two.outer_three"
136
+ end
137
+
138
+ context 'active_if is false' do
139
+ it "invokes given block as a fallback " do
140
+ Chanko::Loader.load("sensitive_inactive_unit")
141
+ expect(controller.invoke(:sensitive_inactive_unit, :outer) { invoke(:sensitive_inactive_unit, :inner) }).to eq(nil)
142
+ end
132
143
  end
133
144
  end
134
145
 
135
146
  context "when run_default is called but no block given" do
136
147
  it "invokes given block as a fallback" do
137
- controller.invoke(:example_unit, :default).should == nil
148
+ expect(controller.invoke(:example_unit, :default)).to eq(nil)
138
149
  end
139
150
  end
140
151
 
141
152
  context "when non-existent unit is specified" do
142
153
  it "does nothing" do
143
- view.invoke(:non_existent_unit, :test, :type => :plain).should == nil
154
+ expect(view.invoke(:non_existent_unit, :test, :type => :plain)).to eq(nil)
144
155
  end
145
156
  end
146
157
 
147
158
  context "when function is not found" do
148
159
  it "runs default but not handled by ExceptionHandler" do
149
- ExceptionHandler.should_not_receive(:handle)
150
- view.invoke(:example_unit, :non_existent_function) { "default" }.should == "default"
160
+ expect(ExceptionHandler).not_to receive(:handle)
161
+ expect(view.invoke(:example_unit, :non_existent_function) { "default" }).to eq("default")
151
162
  end
152
163
  end
153
164
 
@@ -155,22 +166,22 @@ module Chanko
155
166
  context "when block is given" do
156
167
  context "when context is a view" do
157
168
  it "captures given block as a fallback" do
158
- view.should_receive(:capture).and_call_original
159
- view.invoke(:example_unit, :error) { "error" }.should == "error"
169
+ expect(view).to receive(:capture).and_call_original
170
+ expect(view.invoke(:example_unit, :error) { "error" }).to eq("error")
160
171
  end
161
172
  end
162
173
 
163
174
  context "when context is not a view" do
164
175
  it "calls given block as a fallback" do
165
- controller.should_not_receive(:capture)
166
- controller.invoke(:example_unit, :error) { "error" }.should == "error"
176
+ expect(controller).not_to receive(:capture)
177
+ expect(controller.invoke(:example_unit, :error) { "error" }).to eq("error")
167
178
  end
168
179
  end
169
180
  end
170
181
 
171
182
  context "when no block is given" do
172
183
  it "rescues the error and does nothing" do
173
- view.invoke(:example_unit, :error).should == nil
184
+ expect(view.invoke(:example_unit, :error)).to eq(nil)
174
185
  end
175
186
  end
176
187
  end
@@ -9,19 +9,19 @@ module Chanko
9
9
 
10
10
  context "when existent unit name is passed" do
11
11
  it "loads unit in units directory and returns the Module" do
12
- described_class.load(:example_unit).should == ExampleUnit
12
+ expect(described_class.load(:example_unit)).to eq(ExampleUnit)
13
13
  end
14
14
  end
15
15
 
16
16
  context "when non-existent unit name is passed" do
17
17
  it "returns nil" do
18
- described_class.load(:non_existent_unit).should == nil
18
+ expect(described_class.load(:non_existent_unit)).to eq(nil)
19
19
  end
20
20
  end
21
21
 
22
22
  context "when loader has ever loaded specified unit" do
23
23
  it "load unit from cache" do
24
- described_class.any_instance.should_receive(:load_from_file).and_call_original
24
+ expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original
25
25
  described_class.load(:example_unit)
26
26
  described_class.load(:example_unit)
27
27
  end
@@ -33,7 +33,7 @@ module Chanko
33
33
  end
34
34
 
35
35
  it "load unit from cache" do
36
- described_class.any_instance.should_receive(:load_from_file).and_call_original
36
+ expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original
37
37
  described_class.load(:non_existent_unit)
38
38
  described_class.load(:non_existent_unit)
39
39
  end
@@ -53,7 +53,7 @@ module Chanko
53
53
  context "when given Exception" do
54
54
  it "parses and logs it" do
55
55
  described_class.debug(exception)
56
- log.should == lines.join("\n")
56
+ expect(log).to eq(lines.join("\n"))
57
57
  end
58
58
 
59
59
  context "when Config.backtrace_limit is configured" do
@@ -63,7 +63,7 @@ module Chanko
63
63
 
64
64
  it "prints backtrace up to configured depth" do
65
65
  described_class.debug(exception)
66
- log.should == lines[0..5].join("\n")
66
+ expect(log).to eq(lines[0..5].join("\n"))
67
67
  end
68
68
  end
69
69
  end
@@ -71,7 +71,7 @@ module Chanko
71
71
  context "when given String" do
72
72
  it "adds prefix" do
73
73
  described_class.debug("test")
74
- log.should == " [Chanko] test"
74
+ expect(log).to eq(" [Chanko] test")
75
75
  end
76
76
  end
77
77
  end
@@ -83,13 +83,13 @@ module Chanko
83
83
 
84
84
  it "logs nothing" do
85
85
  described_class.debug("test")
86
- log.should == ""
86
+ expect(log).to eq("")
87
87
  end
88
88
  end
89
89
 
90
90
  context "when Rails.logger is nil" do
91
91
  before do
92
- Rails.stub(:logger)
92
+ allow(Rails).to receive(:logger)
93
93
  end
94
94
 
95
95
  it "does notihng" do
@@ -14,14 +14,14 @@ module Chanko
14
14
  describe "#enable_unit" do
15
15
  it "forces to enable specified unit" do
16
16
  enable_unit(:inactive_unit)
17
- view.invoke(:inactive_unit, :inactive, :type => :plain).should == "inactive"
17
+ expect(view.invoke(:inactive_unit, :inactive, :type => :plain)).to eq("inactive")
18
18
  end
19
19
  end
20
20
 
21
21
  describe "#disable_unit" do
22
22
  it "forces to disable specified unit" do
23
23
  disable_unit(:example_unit)
24
- view.invoke(:example_unit, :test).should == nil
24
+ expect(view.invoke(:example_unit, :test)).to eq(nil)
25
25
  end
26
26
  end
27
27
  end
@@ -13,7 +13,7 @@ module Chanko
13
13
  "test"
14
14
  end
15
15
  end
16
- ExampleClass.new.test.should == "test"
16
+ expect(ExampleClass.new.test).to eq("test")
17
17
  end
18
18
 
19
19
  it "extends class methods" do
@@ -24,7 +24,7 @@ module Chanko
24
24
  end
25
25
  end
26
26
  end
27
- ExampleClass.test.should == "test"
27
+ expect(ExampleClass.test).to eq("test")
28
28
  end
29
29
 
30
30
  it "extends instance methods with prefix" do
@@ -33,7 +33,7 @@ module Chanko
33
33
  "test"
34
34
  end
35
35
  end
36
- ExampleClass.new.__prefix_test.should == "test"
36
+ expect(ExampleClass.new.__prefix_test).to eq("test")
37
37
  end
38
38
  end
39
39
  end
@@ -7,28 +7,28 @@ module Chanko
7
7
  context "when identifier is a class" do
8
8
  it "returns identifier with no change" do
9
9
  identifier = ActionView::Base
10
- described_class.find(identifier).should == ActionView::Base
10
+ expect(described_class.find(identifier)).to eq(ActionView::Base)
11
11
  end
12
12
  end
13
13
 
14
14
  context "when identifier is a reserved label" do
15
15
  it "returns reserved class for that" do
16
16
  identifier = :view
17
- described_class.find(identifier).should == ActionView::Base
17
+ expect(described_class.find(identifier)).to eq(ActionView::Base)
18
18
  end
19
19
  end
20
20
 
21
21
  context "when identifier is a string that means a class" do
22
22
  it "returns class of that string" do
23
23
  identifier = "ActionView::Base"
24
- described_class.find(identifier).should == ActionView::Base
24
+ expect(described_class.find(identifier)).to eq(ActionView::Base)
25
25
  end
26
26
  end
27
27
 
28
28
  context "when no class is found" do
29
29
  it "returns nil" do
30
30
  identifier = "Non::Existent::Class"
31
- described_class.find(identifier).should == nil
31
+ expect(described_class.find(identifier)).to eq(nil)
32
32
  end
33
33
  end
34
34
  end
@@ -10,8 +10,8 @@ module Chanko
10
10
  context "when given unit name" do
11
11
  it "returns proxy for specified unit" do
12
12
  proxy = view.unit(:example_unit)
13
- proxy.should be_a UnitProxy
14
- proxy.unit.should == ExampleUnit
13
+ expect(proxy).to be_a UnitProxy
14
+ expect(proxy.unit).to eq(ExampleUnit)
15
15
  end
16
16
  end
17
17
 
@@ -26,7 +26,7 @@ module Chanko
26
26
 
27
27
  it "returns proxy for the top unit of current unit stack" do
28
28
  proxy = view.unit
29
- proxy.unit.should == ExampleUnit
29
+ expect(proxy.unit).to eq(ExampleUnit)
30
30
  end
31
31
  end
32
32
 
@@ -39,10 +39,10 @@ module Chanko
39
39
  end
40
40
 
41
41
  it "change this method name with it" do
42
- view.should_not be_respond_to(:proxy)
42
+ expect(view).not_to be_respond_to(:proxy)
43
43
  proxy = view.proxy(:example_unit)
44
- proxy.should be_a UnitProxy
45
- view.should be_respond_to(:proxy)
44
+ expect(proxy).to be_a UnitProxy
45
+ expect(view).to be_respond_to(:proxy)
46
46
  end
47
47
  end
48
48
 
@@ -55,12 +55,12 @@ module Chanko
55
55
  end
56
56
 
57
57
  it "change this method name with it" do
58
- view.should_not be_respond_to(:proxy1)
59
- view.should_not be_respond_to(:proxy2)
60
- view.proxy1(:example_unit).should be_a UnitProxy
61
- view.proxy2(:example_unit).should be_a UnitProxy
62
- view.should be_respond_to(:proxy1)
63
- view.should be_respond_to(:proxy2)
58
+ expect(view).not_to be_respond_to(:proxy1)
59
+ expect(view).not_to be_respond_to(:proxy2)
60
+ expect(view.proxy1(:example_unit)).to be_a UnitProxy
61
+ expect(view.proxy2(:example_unit)).to be_a UnitProxy
62
+ expect(view).to be_respond_to(:proxy1)
63
+ expect(view).to be_respond_to(:proxy2)
64
64
  end
65
65
  end
66
66
  end
@@ -8,14 +8,14 @@ module Chanko
8
8
 
9
9
  describe "#active?" do
10
10
  it "returns activation status of unit" do
11
- view.unit(:example_unit).should be_active
12
- view.unit(:inactive_unit).should_not be_active
11
+ expect(view.unit(:example_unit)).to be_active
12
+ expect(view.unit(:inactive_unit)).not_to be_active
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#method_missing" do
17
17
  it "calls prefixed method" do
18
- view.should_receive(:__example_unit_test)
18
+ expect(view).to receive(:__example_unit_test)
19
19
  view.unit(:example_unit).test
20
20
  end
21
21
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  module Chanko
4
4
  describe Unit do
5
5
  before do
6
- unit.stub(:name => "ExampleUnit")
6
+ allow(unit).to receive_messages(:name => "ExampleUnit")
7
7
  end
8
8
 
9
9
  let(:unit) do
@@ -29,7 +29,7 @@ module Chanko
29
29
  describe ".active_if" do
30
30
  context "in default configuration" do
31
31
  it "is configured to return always true" do
32
- should be_true
32
+ is_expected.to eq(true)
33
33
  end
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ module Chanko
38
38
  unit.active_if(:true, :false)
39
39
  end
40
40
  specify "all of defined conditions must pass" do
41
- should be_false
41
+ is_expected.to eq(false)
42
42
  end
43
43
  end
44
44
 
@@ -47,7 +47,7 @@ module Chanko
47
47
  unit.active_if(:true) { false }
48
48
  end
49
49
  specify "all of defined conditions and block must pass" do
50
- should be_false
50
+ is_expected.to eq(false)
51
51
  end
52
52
  end
53
53
 
@@ -69,7 +69,7 @@ module Chanko
69
69
  active_if any(:true, :false)
70
70
  end
71
71
  end
72
- it { should be_true }
72
+ it { is_expected.to eq(true) }
73
73
  end
74
74
 
75
75
  context "when all conditions returned false" do
@@ -78,7 +78,7 @@ module Chanko
78
78
  active_if any(:false, :false)
79
79
  end
80
80
  end
81
- it { should be_false }
81
+ it { is_expected.to eq(false) }
82
82
  end
83
83
  end
84
84
 
@@ -89,7 +89,7 @@ module Chanko
89
89
  active_if none(:false, :false)
90
90
  end
91
91
  end
92
- it { should be_true }
92
+ it { is_expected.to eq(true) }
93
93
  end
94
94
 
95
95
  context "when conditions returned true and false" do
@@ -98,7 +98,7 @@ module Chanko
98
98
  active_if none(:true, :false)
99
99
  end
100
100
  end
101
- it { should be_false }
101
+ it { is_expected.to eq(false) }
102
102
  end
103
103
  end
104
104
 
@@ -110,7 +110,7 @@ module Chanko
110
110
  end
111
111
  end
112
112
  it "returns negatived result of inner-expression" do
113
- should be_false
113
+ is_expected.to eq(false)
114
114
  end
115
115
  end
116
116
 
@@ -121,7 +121,7 @@ module Chanko
121
121
  end
122
122
  end
123
123
  it "uses none(:true) as false" do
124
- should be_false
124
+ is_expected.to eq(false)
125
125
  end
126
126
  end
127
127
 
@@ -131,7 +131,7 @@ module Chanko
131
131
  active_if any(any(none(:false), :false), :false)
132
132
  end
133
133
  end
134
- it { should be_true }
134
+ it { is_expected.to eq(true) }
135
135
  end
136
136
  end
137
137
  end
@@ -139,13 +139,13 @@ module Chanko
139
139
  describe ".scope" do
140
140
  specify "given scope is recorded to used scope list" do
141
141
  unit.scope(:view) { }
142
- unit.scopes.keys.should == [ActionView::Base]
142
+ expect(unit.scopes.keys).to eq([ActionView::Base])
143
143
  end
144
144
 
145
145
  context "in the scoped block" do
146
146
  specify "current_scope returns given scope" do
147
147
  unit.scope(:view) do
148
- unit.current_scope.should == ActionView::Base
148
+ expect(unit.current_scope).to eq(ActionView::Base)
149
149
  end
150
150
  end
151
151
  end
@@ -153,7 +153,7 @@ module Chanko
153
153
  context "out of the scoped block" do
154
154
  specify "current_scope returns nil" do
155
155
  unit.scope(:view) { }
156
- unit.current_scope.should == nil
156
+ expect(unit.current_scope).to eq(nil)
157
157
  end
158
158
  end
159
159
  end
@@ -165,7 +165,7 @@ module Chanko
165
165
  "test"
166
166
  end
167
167
  end
168
- unit.scopes[ActionView::Base][:test].block.call.should == "test"
168
+ expect(unit.scopes[ActionView::Base][:test].block.call).to eq("test")
169
169
  end
170
170
  end
171
171
 
@@ -174,7 +174,7 @@ module Chanko
174
174
  unit.shared(:test) do
175
175
  "test"
176
176
  end
177
- unit.shared_methods[:test].call.should == "test"
177
+ expect(unit.shared_methods[:test].call).to eq("test")
178
178
  end
179
179
  end
180
180
 
@@ -185,7 +185,7 @@ module Chanko
185
185
  "test"
186
186
  end
187
187
  end
188
- view.__example_unit_test.should == "test"
188
+ expect(view.__example_unit_test).to eq("test")
189
189
  end
190
190
  end
191
191
 
@@ -230,25 +230,25 @@ module Chanko
230
230
  end
231
231
 
232
232
  it "defines instance methods with prefix" do
233
- ExampleModel.new.__example_unit_test.should == "test"
233
+ expect(ExampleModel.new.__example_unit_test).to eq("test")
234
234
  end
235
235
 
236
236
  it "defines class methods with prefix" do
237
- ExampleModel.__example_unit_test.should == "test"
237
+ expect(ExampleModel.__example_unit_test).to eq("test")
238
238
  end
239
239
 
240
240
  it "defines scope method with prefix" do
241
- ExampleModel.__example_unit_active.should == "scoped"
241
+ expect(ExampleModel.__example_unit_active).to eq("scoped")
242
242
  end
243
243
 
244
244
  it "defines has_one association method with prefix" do
245
- ExampleModel.__example_unit_user.should == [:class_name => "User"]
245
+ expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
246
246
  end
247
247
  end
248
248
 
249
249
  describe ".view_path" do
250
250
  it "returns path for its view directory" do
251
- unit.view_path.should == "#{Config.units_directory_path}/example_unit/views"
251
+ expect(unit.view_path).to eq("#{Config.units_directory_path}/example_unit/views")
252
252
  end
253
253
  end
254
254
  end
@@ -8,7 +8,7 @@ describe ApplicationController do
8
8
  end
9
9
 
10
10
  it "clears cache before each request" do
11
- Chanko::Loader.cache.should_receive(:clear).exactly(2)
11
+ expect(Chanko::Loader.cache).to receive(:clear).exactly(2)
12
12
  get :index
13
13
  get :index
14
14
  end
@@ -0,0 +1,9 @@
1
+ module SensitiveInactiveUnit
2
+ include Chanko::Unit
3
+ active_if { false }
4
+
5
+ scope(:controller) do
6
+ function(:outer) {}
7
+ function(:innner) {}
8
+ end
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,19 +12,32 @@ require "chanko"
12
12
 
13
13
  require File.expand_path("../dummy/config/environment", __FILE__)
14
14
  require "rspec/rails"
15
- require "rspec/autorun"
16
15
 
17
16
  RSpec.configure do |config|
18
17
  config.use_transactional_fixtures = true
19
18
  config.infer_base_class_for_anonymous_controllers = false
20
- config.treat_symbols_as_metadata_keys_with_true_values = true
21
19
  config.run_all_when_everything_filtered = true
22
20
  config.filter_run :focus
23
21
 
22
+ config.expect_with :rspec do |expectations|
23
+ expectations.syntax = :expect
24
+ end
25
+
24
26
  config.after do
25
27
  Chanko::Config.reset
26
28
  Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
27
29
  end
30
+
31
+ # rspec-rails 3 will no longer automatically infer an example group's spec type
32
+ # from the file location. You can explicitly opt-in to the feature using this
33
+ # config option.
34
+ # To explicitly tag specs without using automatic inference, set the `:type`
35
+ # metadata manually:
36
+ #
37
+ # describe ThingsController, :type => :controller do
38
+ # # Equivalent to being in spec/controllers
39
+ # end
40
+ config.infer_spec_type_from_file_location!
28
41
  end
29
42
 
30
43
  Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chanko
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 2.12.2
89
+ version: 3.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 2.12.2
96
+ version: 3.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sass-rails
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -279,6 +279,7 @@ files:
279
279
  - spec/fixtures/units/example_unit/views/_test.html.erb
280
280
  - spec/fixtures/units/inactive_unit/inactive_unit.rb
281
281
  - spec/fixtures/units/insensitive_unit/insensitive_unit.rb
282
+ - spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb
282
283
  - spec/fixtures/units/sensitive_unit/sensitive_unit.rb
283
284
  - spec/spec_helper.rb
284
285
  homepage: https://github.com/cookpad/chanko
@@ -367,5 +368,6 @@ test_files:
367
368
  - spec/fixtures/units/example_unit/views/_test.html.erb
368
369
  - spec/fixtures/units/inactive_unit/inactive_unit.rb
369
370
  - spec/fixtures/units/insensitive_unit/insensitive_unit.rb
371
+ - spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb
370
372
  - spec/fixtures/units/sensitive_unit/sensitive_unit.rb
371
373
  - spec/spec_helper.rb