rspec-action_view 0.1.2 → 0.2.0
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 +33 -31
- data/VERSION +1 -1
- data/lib/rspec-action_view/erb_template_inline.rb +89 -0
- data/lib/rspec-action_view/rspec/example_group.rb +13 -0
- data/lib/rspec-action_view/rspec/macro.rb +26 -0
- data/lib/rspec-action_view.rb +5 -48
- data/rspec-action_view.gemspec +7 -4
- data/spec/rspec-action_view/erb_tester_spec.rb +39 -0
- metadata +8 -5
- data/spec/rspec-action_view_spec.rb +0 -52
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rspec for Rails 3 ActionView
|
2
2
|
|
3
|
-
RSpec 2 library to make it simple to spec Rails 3 ActionView extensions
|
3
|
+
RSpec 2 library to make it simple to spec Rails 3 ActionView extensions.
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
@@ -9,39 +9,41 @@ RSpec 2 library to make it simple to spec Rails 3 ActionView extensions
|
|
9
9
|
## Usage
|
10
10
|
|
11
11
|
<pre>
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module MyView
|
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
|
+
|
20
|
+
module Say
|
21
|
+
def hello(clazz, &block)
|
22
|
+
content = with_output_buffer(&block)
|
23
|
+
content_tag :div, content, :class => clazz
|
16
24
|
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
view.with_template do %{
|
39
|
-
<%= tab_for('kristian') { 'hello' } %>
|
40
|
-
}
|
41
|
-
end.should match /hello/
|
42
|
-
end
|
26
|
+
def name
|
27
|
+
'Kristian'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'My View extensions!' do
|
33
|
+
extend_view_with MyView, :tab, :say
|
34
|
+
|
35
|
+
it "should work" do
|
36
|
+
with_engine(:erb) do |e|
|
37
|
+
e.run_template("hello <%= name %>").should match /Kristian/
|
38
|
+
|
39
|
+
e.run_template do
|
40
|
+
%{<%= tab_for :x do %>
|
41
|
+
<%= hello :blip do %>
|
42
|
+
ged
|
43
|
+
<% end %>
|
44
|
+
<% end %>}
|
45
|
+
end.should match /ged/
|
43
46
|
end
|
44
|
-
|
45
47
|
end
|
46
48
|
end
|
47
49
|
</pre>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'action_view/context'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module ActionView
|
6
|
+
class ERBTemplateEngine
|
7
|
+
|
8
|
+
ERBHandler = ::ActionView::Template::Handlers::ERB
|
9
|
+
|
10
|
+
attr_accessor :output_buffer, :rendered
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@output_buffer = ActiveSupport::SafeBuffer.new
|
14
|
+
@rendered = ''
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(options = {}, local_assigns = {}, &block)
|
18
|
+
view.assign(_assigns)
|
19
|
+
output = view.render(options, local_assigns, &block)
|
20
|
+
@rendered << output
|
21
|
+
output
|
22
|
+
end
|
23
|
+
|
24
|
+
module Locals
|
25
|
+
attr_accessor :locals
|
26
|
+
end
|
27
|
+
|
28
|
+
def locals
|
29
|
+
@locals ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def _get_view
|
33
|
+
view = ::ActionView::Base.new
|
34
|
+
|
35
|
+
# ???
|
36
|
+
# view.singleton_class.send :include, _helpers
|
37
|
+
|
38
|
+
view.extend(Locals)
|
39
|
+
view.locals = self.locals
|
40
|
+
view.output_buffer = self.output_buffer
|
41
|
+
view
|
42
|
+
end
|
43
|
+
|
44
|
+
def view
|
45
|
+
@view ||= _get_view
|
46
|
+
end
|
47
|
+
|
48
|
+
alias_method :_view, :view
|
49
|
+
|
50
|
+
EXCLUDE_IVARS = %w{
|
51
|
+
@_assertion_wrapped
|
52
|
+
@_result
|
53
|
+
@controller
|
54
|
+
@layouts
|
55
|
+
@locals
|
56
|
+
@method_name
|
57
|
+
@output_buffer
|
58
|
+
@partials
|
59
|
+
@rendered
|
60
|
+
@request
|
61
|
+
@routes
|
62
|
+
@templates
|
63
|
+
@test_passed
|
64
|
+
@view
|
65
|
+
@view_context_class
|
66
|
+
}
|
67
|
+
|
68
|
+
def _instance_variables
|
69
|
+
instance_variables.map(&:to_s) - EXCLUDE_IVARS
|
70
|
+
end
|
71
|
+
|
72
|
+
def _assigns
|
73
|
+
_instance_variables.inject({}) do |hash, var|
|
74
|
+
name = var[1..-1].to_sym
|
75
|
+
hash[name] = instance_variable_get(var)
|
76
|
+
hash
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def run_template content=nil, &block
|
81
|
+
content ||= yield
|
82
|
+
render :inline => content
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RSpec::Core
|
2
|
+
class ExampleGroup
|
3
|
+
def with_engine type = :erb, &block
|
4
|
+
engine = RSpec::ActionView::ERBTemplateEngine.new
|
5
|
+
|
6
|
+
if block
|
7
|
+
block.arity < 1 ? engine.instance_eval(&block) : block.call(engine)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# include RSpec::ActionView::Macro
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/railtie'
|
2
|
+
require 'rails3_plugin_toolbox'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module ActionView
|
6
|
+
module Macro
|
7
|
+
def extend_view_with_modules *modules
|
8
|
+
Rails3::PluginExtender.new do
|
9
|
+
# extend action_view with methods from some modules
|
10
|
+
extend_rails :view do
|
11
|
+
extend_with *modules
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def extend_view_with base_name, *modules
|
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
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rspec-action_view.rb
CHANGED
@@ -1,51 +1,8 @@
|
|
1
1
|
require 'rspec'
|
2
|
-
require '
|
3
|
-
require 'active_support/railtie'
|
4
|
-
require 'action_view/template/handlers/erb'
|
2
|
+
require 'require_all'
|
5
3
|
|
6
|
-
|
7
|
-
include ActionView::Helpers::TagHelper
|
8
|
-
include ActionView::Helpers::CaptureHelper
|
4
|
+
require_all File.dirname(__FILE__) + '/rspec-action_view'
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
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
|
-
|
23
|
-
def with_output_buffer(buf = nil)
|
24
|
-
yield
|
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
|
33
|
-
|
34
|
-
def self.tests *helpers
|
35
|
-
helpers.flatten.each do |name|
|
36
|
-
include name.to_s.camelize.constantize
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
module RSpec::Core
|
42
|
-
class ExampleGroup
|
43
|
-
def with_action_view &block
|
44
|
-
block.call(ActionViewTester.new)
|
45
|
-
end
|
46
|
-
|
47
|
-
def setup_action_view &block
|
48
|
-
ActionViewTester.instance_eval(&block)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.extend RSpec::ActionView::Macro
|
8
|
+
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.2.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-25}
|
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 = [
|
@@ -25,8 +25,11 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/rspec-action_view.rb",
|
28
|
+
"lib/rspec-action_view/erb_template_inline.rb",
|
29
|
+
"lib/rspec-action_view/rspec/example_group.rb",
|
30
|
+
"lib/rspec-action_view/rspec/macro.rb",
|
28
31
|
"rspec-action_view.gemspec",
|
29
|
-
"spec/rspec-
|
32
|
+
"spec/rspec-action_view/erb_tester_spec.rb",
|
30
33
|
"spec/spec_helper.rb"
|
31
34
|
]
|
32
35
|
s.homepage = %q{http://github.com/kristianmandrup/rspec-action_view}
|
@@ -35,7 +38,7 @@ Gem::Specification.new do |s|
|
|
35
38
|
s.rubygems_version = %q{1.3.7}
|
36
39
|
s.summary = %q{RSpec for Rails 3 ActionView extensions}
|
37
40
|
s.test_files = [
|
38
|
-
"spec/rspec-
|
41
|
+
"spec/rspec-action_view/erb_tester_spec.rb",
|
39
42
|
"spec/spec_helper.rb"
|
40
43
|
]
|
41
44
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module MyView
|
4
|
+
module Tab
|
5
|
+
def tab_for(clazz, &block)
|
6
|
+
content = with_output_buffer(&block)
|
7
|
+
content_tag :li, content, :class => clazz
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Say
|
12
|
+
def hello(clazz, &block)
|
13
|
+
content = with_output_buffer(&block)
|
14
|
+
content_tag :div, content, :class => clazz
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
'Kristian'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'My View extensions!' do
|
24
|
+
extend_view_with MyView, :tab, :say
|
25
|
+
|
26
|
+
it "should work" do
|
27
|
+
with_engine(:erb) do |e|
|
28
|
+
e.run_template("hello <%= name %>").should match /Kristian/
|
29
|
+
|
30
|
+
e.run_template do
|
31
|
+
%{<%= tab_for :x do %>
|
32
|
+
<%= hello :blip do %>
|
33
|
+
ged
|
34
|
+
<% end %>
|
35
|
+
<% end %>}
|
36
|
+
end.should match /ged/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.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-25 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -50,8 +50,11 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- VERSION
|
52
52
|
- lib/rspec-action_view.rb
|
53
|
+
- lib/rspec-action_view/erb_template_inline.rb
|
54
|
+
- lib/rspec-action_view/rspec/example_group.rb
|
55
|
+
- lib/rspec-action_view/rspec/macro.rb
|
53
56
|
- rspec-action_view.gemspec
|
54
|
-
- spec/rspec-
|
57
|
+
- spec/rspec-action_view/erb_tester_spec.rb
|
55
58
|
- spec/spec_helper.rb
|
56
59
|
has_rdoc: true
|
57
60
|
homepage: http://github.com/kristianmandrup/rspec-action_view
|
@@ -86,5 +89,5 @@ signing_key:
|
|
86
89
|
specification_version: 3
|
87
90
|
summary: RSpec for Rails 3 ActionView extensions
|
88
91
|
test_files:
|
89
|
-
- spec/rspec-
|
92
|
+
- spec/rspec-action_view/erb_tester_spec.rb
|
90
93
|
- spec/spec_helper.rb
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module MyViewHelper
|
4
|
-
def tab_for(clazz, &block)
|
5
|
-
content = with_output_buffer(&block)
|
6
|
-
content_tag :li, content, :class => clazz
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module MyOtherViewHelper
|
11
|
-
def hello(clazz, &block)
|
12
|
-
content = with_output_buffer(&block)
|
13
|
-
content_tag :div, content, :class => clazz
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
describe "My ViewHelpers" do
|
20
|
-
it "should render content as expected" do
|
21
|
-
setup_action_view do
|
22
|
-
tests MyViewHelper, MyOtherViewHelper
|
23
|
-
end
|
24
|
-
|
25
|
-
with_action_view do |view|
|
26
|
-
view.tab_for('kristian') { 'hello' }.should match /kristian/
|
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
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|