-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
view_example_group.rb
81 lines (72 loc) · 2.23 KB
/
view_example_group.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'webrat'
require 'rspec/rails/view_assigns'
module RSpec::Rails
# Extends ActionView::TestCase::Behavior
#
# == Examples
#
# describe "widgets/index.html.erb" do
# it "renders the @widgets" do
# widgets = [
# stub_model(Widget, :name => "Foo"),
# stub_model(Widget, :name => "Bar")
# ]
# assign(:widgets, widgets)
# render
# rendered.should contain("Foo")
# rendered.should contain("Bar")
# end
# end
#
module ViewExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
include ActionView::TestCase::Behavior
include RSpec::Rails::ViewAssigns
include Webrat::Matchers
module InstanceMethods
def response
RSpec.deprecate("response", "rendered")
rendered
end
# :callseq:
# render
# render(:template => "widgets/new.html.erb")
# render({:partial => "widgets/widget.html.erb"}, {... locals ...})
# render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end
#
# Delegates to ActionView::Base#render, so see documentation on that for more
# info.
#
# The only addition is that you can call render with no arguments, and RSpec
# will pass the top level description to render:
#
# describe "widgets/new.html.erb" do
# it "shows all the widgets" do
# render # => view.render(:file => "widgets/new.html.erb")
# ...
# end
# end
def render(options={}, local_assigns={}, &block)
options = {:template => _default_file_to_render} if Hash === options and options.empty?
super(options, local_assigns, &block)
end
private
def _default_file_to_render
running_example.example_group.top_level_description
end
def _controller_path
_default_file_to_render.split("/")[0..-2].join("/")
end
end
included do
before do
controller.controller_path = _controller_path
end
end
RSpec.configure do |c|
c.include self, :example_group => { :file_path => /\bspec\/views\// }
end
end
end