rspec-action_view 0.1.0 → 0.1.2
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.
- data/README.markdown +24 -1
- data/VERSION +1 -1
- data/lib/rspec-action_view.rb +15 -1
- data/rspec-action_view.gemspec +1 -1
- data/spec/rspec-action_view_spec.rb +23 -0
- metadata +2 -2
data/README.markdown
CHANGED
@@ -18,7 +18,30 @@ RSpec 2 library to make it simple to spec Rails 3 ActionView extensions
|
|
18
18
|
with_action_view do |view|
|
19
19
|
view.tab_for('kristian') { 'hello' }.should match /kristian/
|
20
20
|
view.hello('david') { 'hello' }.should match /david/
|
21
|
-
end
|
21
|
+
end
|
22
|
+
|
23
|
+
with_action_view do |view|
|
24
|
+
|
25
|
+
view.set :posts => ['post 1', 'post 2'], :title => 'Blog posts index'
|
26
|
+
view.instance_variable_get('@posts').should have(2).items
|
27
|
+
|
28
|
+
res = view.with_template(%{
|
29
|
+
<%= @title %>
|
30
|
+
<%= tab_for('kristian') { 'hello' } %>
|
31
|
+
<%= @posts.join(',') %>
|
32
|
+
})
|
33
|
+
res.should match /hello/
|
34
|
+
res.should match /Blog posts index/
|
35
|
+
res.should match /post 1/
|
36
|
+
|
37
|
+
with_action_view do |view|
|
38
|
+
view.with_template do %{
|
39
|
+
<%= tab_for('kristian') { 'hello' } %>
|
40
|
+
}
|
41
|
+
end.should match /hello/
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
22
45
|
end
|
23
46
|
end
|
24
47
|
</pre>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/rspec-action_view.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'rspec'
|
2
2
|
require 'action_view'
|
3
3
|
require 'active_support/railtie'
|
4
4
|
require 'action_view/template/handlers/erb'
|
@@ -13,9 +13,23 @@ class ActionViewTester
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def set attributes={}
|
17
|
+
attributes.each do |key, value|
|
18
|
+
instance_var = "@#{key}"
|
19
|
+
instance_variable_set(instance_var, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
16
23
|
def with_output_buffer(buf = nil)
|
17
24
|
yield
|
18
25
|
end
|
26
|
+
|
27
|
+
def with_template content=nil, &block
|
28
|
+
require 'erb'
|
29
|
+
content ||= yield
|
30
|
+
template = ERB.new content
|
31
|
+
template.result(binding)
|
32
|
+
end
|
19
33
|
|
20
34
|
def self.tests *helpers
|
21
35
|
helpers.flatten.each do |name|
|
data/rspec-action_view.gemspec
CHANGED
@@ -15,6 +15,7 @@ module MyOtherViewHelper
|
|
15
15
|
end
|
16
16
|
|
17
17
|
|
18
|
+
|
18
19
|
describe "My ViewHelpers" do
|
19
20
|
it "should render content as expected" do
|
20
21
|
setup_action_view do
|
@@ -24,6 +25,28 @@ describe "My ViewHelpers" do
|
|
24
25
|
with_action_view do |view|
|
25
26
|
view.tab_for('kristian') { 'hello' }.should match /kristian/
|
26
27
|
view.hello('david') { 'hello' }.should match /david/
|
28
|
+
|
29
|
+
with_action_view do |view|
|
30
|
+
view.set :posts => ['post 1', 'post 2'], :title => 'Blog posts index'
|
31
|
+
view.instance_variable_get('@posts').should have(2).items
|
32
|
+
|
33
|
+
res = view.with_template do %{
|
34
|
+
<%= @title %>
|
35
|
+
<%= tab_for('kristian') { 'hello' } %>
|
36
|
+
<%= @posts.join(',') %>
|
37
|
+
}
|
38
|
+
end
|
39
|
+
res.should match /hello/
|
40
|
+
res.should match /Blog posts index/
|
41
|
+
res.should match /post 1/
|
42
|
+
|
43
|
+
with_action_view do |view|
|
44
|
+
view.with_template do %{
|
45
|
+
<%= tab_for('kristian') { 'hello' } %>
|
46
|
+
}
|
47
|
+
end.should match /hello/
|
48
|
+
end
|
49
|
+
end
|
27
50
|
end
|
28
51
|
end
|
29
52
|
end
|