rspec-action_view 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +18 -3
- data/VERSION +1 -1
- data/lib/rspec-action_view/erb_template_inline.rb +9 -3
- data/lib/rspec-action_view/rspec/macro.rb +10 -13
- data/rspec-action_view.gemspec +5 -3
- data/spec/rspec-action_view/assign_locals_spec.rb +41 -0
- data/spec/rspec-action_view/erb_tester_spec.rb +47 -2
- metadata +5 -3
data/README.markdown
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Rspec for Rails 3 ActionView
|
2
2
|
|
3
3
|
RSpec 2 library to make it simple to spec Rails 3 ActionView extensions.
|
4
|
+
Works with locals, #html_safe and nested blocks using #with_output_buffer and much, much more...
|
5
|
+
|
6
|
+
Enjoy! I know I am... ;)
|
4
7
|
|
5
8
|
## Install
|
6
9
|
|
@@ -23,8 +26,12 @@ RSpec 2 library to make it simple to spec Rails 3 ActionView extensions.
|
|
23
26
|
content_tag :div, content, :class => clazz
|
24
27
|
end
|
25
28
|
|
26
|
-
def
|
27
|
-
'Kristian'
|
29
|
+
def my_name
|
30
|
+
'Kristian'.html_safe
|
31
|
+
end
|
32
|
+
|
33
|
+
def hi(first_name_, last_name)
|
34
|
+
"Hi #{first_name} #{last_name} !".html_safe
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -34,7 +41,7 @@ RSpec 2 library to make it simple to spec Rails 3 ActionView extensions.
|
|
34
41
|
|
35
42
|
it "should work" do
|
36
43
|
with_engine(:erb) do |e|
|
37
|
-
e.run_template
|
44
|
+
e.run_template {"hello <%= my_name %>"}.should match /Kristian/
|
38
45
|
|
39
46
|
e.run_template do
|
40
47
|
%{<%= tab_for :x do %>
|
@@ -45,6 +52,14 @@ RSpec 2 library to make it simple to spec Rails 3 ActionView extensions.
|
|
45
52
|
end.should match /ged/
|
46
53
|
end
|
47
54
|
end
|
55
|
+
|
56
|
+
it "should assign Kristian to the local 'name' that is used in the erb" do
|
57
|
+
with_engine(:erb) do |e|
|
58
|
+
e.run_template_locals :first_name => 'Kristian', :last_name => 'Mandrup' do
|
59
|
+
%{<%= hi(first_name, last_name) %>}
|
60
|
+
end.should match /Kristian/
|
61
|
+
end
|
62
|
+
end
|
48
63
|
end
|
49
64
|
</pre>
|
50
65
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -77,9 +77,15 @@ module RSpec
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
80
|
+
def run_template_locals locals = {}, local_assigns = {}, &block
|
81
|
+
raise ArgumentError, "Must take template as a block argument" if !block
|
82
|
+
options = {:inline => block.call}
|
83
|
+
render options.merge(:locals => locals), {}
|
84
|
+
end
|
85
|
+
|
86
|
+
def run_template options = {}, local_assigns = {}, &block
|
87
|
+
raise ArgumentError, "Must take template as a block argument" if !block
|
88
|
+
render options.merge(:inline => block.call), local_assigns
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
@@ -1,24 +1,21 @@
|
|
1
1
|
require 'active_support/railtie'
|
2
2
|
require 'rails3_plugin_toolbox'
|
3
|
+
require 'sugar-high/kind_of'
|
3
4
|
|
4
5
|
module RSpec
|
5
6
|
module ActionView
|
6
7
|
module Macro
|
7
|
-
def
|
8
|
+
def extend_view_with base_name, *modules
|
9
|
+
modules = modules.flatten
|
8
10
|
Rails3::PluginExtender.new do
|
9
11
|
# extend action_view with methods from some modules
|
10
|
-
extend_rails :view do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Rails3::PluginExtender.new do
|
18
|
-
# extend action_view with methods from some modules
|
19
|
-
extend_rails :view do
|
20
|
-
extend_from_module base_name, *modules
|
21
|
-
end
|
12
|
+
extend_rails :view do |v|
|
13
|
+
if base_name.kind_of?(Module) && !modules.empty? && modules.only_kinds_of?(Symbol)
|
14
|
+
v.extend_from_module(base_name, *modules)
|
15
|
+
else
|
16
|
+
v.extend_with base_name, *modules
|
17
|
+
end
|
18
|
+
end
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
data/rspec-action_view.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rspec-action_view}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-26}
|
13
13
|
s.description = %q{RSpec 2 library to make it simple to spec Rails 3 ActionView extensions}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/rspec-action_view/rspec/example_group.rb",
|
30
30
|
"lib/rspec-action_view/rspec/macro.rb",
|
31
31
|
"rspec-action_view.gemspec",
|
32
|
+
"spec/rspec-action_view/assign_locals_spec.rb",
|
32
33
|
"spec/rspec-action_view/erb_tester_spec.rb",
|
33
34
|
"spec/spec_helper.rb"
|
34
35
|
]
|
@@ -38,7 +39,8 @@ Gem::Specification.new do |s|
|
|
38
39
|
s.rubygems_version = %q{1.3.7}
|
39
40
|
s.summary = %q{RSpec for Rails 3 ActionView extensions}
|
40
41
|
s.test_files = [
|
41
|
-
"spec/rspec-action_view/
|
42
|
+
"spec/rspec-action_view/assign_locals_spec.rb",
|
43
|
+
"spec/rspec-action_view/erb_tester_spec.rb",
|
42
44
|
"spec/spec_helper.rb"
|
43
45
|
]
|
44
46
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MyView
|
4
|
+
|
5
|
+
def goodbye name
|
6
|
+
"Goodbye #{name}".html_safe
|
7
|
+
end
|
8
|
+
|
9
|
+
def hello name
|
10
|
+
"Hello #{name}".html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
module Tab
|
14
|
+
def tab_for(clazz, &block)
|
15
|
+
content = with_output_buffer(&block)
|
16
|
+
content_tag :li, content, :class => clazz
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'My View extensions!' do
|
22
|
+
extend_view_with MyView
|
23
|
+
|
24
|
+
describe '#run_template' do
|
25
|
+
it "should assign Kristian to the local 'name' that is used in the erb" do
|
26
|
+
with_engine(:erb) do |e|
|
27
|
+
e.run_template(:locals => {:name => 'Kristian'}) {"<%= goodbye name %>"}.should match /Kristian/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#run_template_locals' do
|
33
|
+
it "should assign Kristian to the local 'name' that is used in the erb" do
|
34
|
+
with_engine(:erb) do |e|
|
35
|
+
e.run_template_locals :name => 'Kristian' do
|
36
|
+
%{<%= goodbye name %>}
|
37
|
+
end.should match /Kristian/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module MyView
|
4
|
+
|
5
|
+
def goodbye
|
6
|
+
'Goodbye'
|
7
|
+
end
|
8
|
+
|
4
9
|
module Tab
|
5
10
|
def tab_for(clazz, &block)
|
6
11
|
content = with_output_buffer(&block)
|
@@ -8,6 +13,18 @@ module MyView
|
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
16
|
+
module Blip
|
17
|
+
def blip
|
18
|
+
content_tag :li, 'blip me'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Blap
|
23
|
+
def blap
|
24
|
+
content_tag :li, 'blap me'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
module Say
|
12
29
|
def hello(clazz, &block)
|
13
30
|
content = with_output_buffer(&block)
|
@@ -22,11 +39,38 @@ end
|
|
22
39
|
|
23
40
|
describe 'My View extensions!' do
|
24
41
|
extend_view_with MyView, :tab, :say
|
42
|
+
extend_view_with MyView
|
43
|
+
extend_view_with MyView::Blap, 'MyView::Blip'
|
44
|
+
|
45
|
+
it "should extend with single module MyView" do
|
46
|
+
with_engine(:erb) do |e|
|
47
|
+
e.run_template {"<%= goodbye %>"}.should match /Goodbye/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
it "should extend with module Say - hello, name" do
|
53
|
+
with_engine(:erb) do |e|
|
54
|
+
e.run_template {"hello <%= name %>"}.should match /Kristian/
|
25
55
|
|
26
|
-
|
56
|
+
e.run_template do
|
57
|
+
%{
|
58
|
+
<%= hello :blip do %>
|
59
|
+
ged
|
60
|
+
<% end %>
|
61
|
+
}
|
62
|
+
end.should match /ged/
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should extend with modules Blip and Blap" do
|
27
67
|
with_engine(:erb) do |e|
|
28
|
-
e.run_template
|
68
|
+
e.run_template {"hello <%= blip %> go <%= blap %>"}.should match /blip me/
|
69
|
+
end
|
70
|
+
end
|
29
71
|
|
72
|
+
it "should extend handle nested blocks in ERB" do
|
73
|
+
with_engine(:erb) do |e|
|
30
74
|
e.run_template do
|
31
75
|
%{<%= tab_for :x do %>
|
32
76
|
<%= hello :blip do %>
|
@@ -36,4 +80,5 @@ describe 'My View extensions!' do
|
|
36
80
|
end.should match /ged/
|
37
81
|
end
|
38
82
|
end
|
83
|
+
|
39
84
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-26 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/rspec-action_view/rspec/example_group.rb
|
55
55
|
- lib/rspec-action_view/rspec/macro.rb
|
56
56
|
- rspec-action_view.gemspec
|
57
|
+
- spec/rspec-action_view/assign_locals_spec.rb
|
57
58
|
- spec/rspec-action_view/erb_tester_spec.rb
|
58
59
|
- spec/spec_helper.rb
|
59
60
|
has_rdoc: true
|
@@ -89,5 +90,6 @@ signing_key:
|
|
89
90
|
specification_version: 3
|
90
91
|
summary: RSpec for Rails 3 ActionView extensions
|
91
92
|
test_files:
|
93
|
+
- spec/rspec-action_view/assign_locals_spec.rb
|
92
94
|
- spec/rspec-action_view/erb_tester_spec.rb
|
93
95
|
- spec/spec_helper.rb
|