How can I test my ActionView extensions (e.g. a new helper) without using full Rails stack?
I use RSpec, so I have somehow to render a template from my /spec/views/ folder from spec_helper.rb. What is the best way to do that?
How can I test my ActionView extensions (e.g. a new helper) without using full Rails stack?
I use RSpec, so I have somehow to render a template from my /spec/views/ folder from spec_helper.rb. What is the best way to do that?
I'll maybe not answer your question but you can use RSpec with the rspec-rails gem. No need then to test outside the Rails stack.
https://github.com/rspec/rspec-rails
Here is an example :
describe "lists/show.html.erb" do
before(:each) do
assign :new_link, Link.new
@link = mock_model(Link,
:title => "Link's title",
:url => "http://wwww.link.s.url/")
@list = mock_model(List,
:title => "Some title",
:links => [@link])
end
it "displays the list's title" do
render
rendered.should have_content(@list.title)
end
it "displays the links's title and URL" do
render
rendered.should have_link(@link.title,
:href => @link.url)
end
end
You will have to adapt your Gemfile (see the link beyond) and to run bundle update
& rails rspec:install
.