View Specs / Edits
Edited line 2 :
Edited line 7 :
Posts being the name of my controller.
fake_request is a helper (TODO: explain more)
Posts being the name of my controller.
fake_request is a helper (TODO: explain more)
Edited line 15 :
In this example we are creating a controller instance variable called @posts, it’s an array containing one instance of the Post object with 2 attributes set: id and body.
In this example we are creating a controller instance variable called @posts, it’s an array containing one instance of the Post object with 2 attributes set: id and body.
Edited line 7 :
Posts being the name of my controller.
Posts being the name of my controller
Edited line 5 :
@controller = Posts.new(fake_request)
@controller = Posts.new(fake_request)
Edited line 9 :
Posts being the name of my controller
fake_request is a helper (TODO: explain more)
Posts being the name of my controller
fake_request is a helper (TODO: explain more)
Edited line 15 :
@controller.instance_variable_set(:@posts, [Post.new(:id => 1, :body => "Merb!")])
@controller.instance_variable_set(:@posts, [Post.new(:id => 1, :body => "Merb!")])
Edited line 25 :
describe "posts/index" do
describe "posts/index" do
Edited line 45 :
Edited line 16 :
Edited line 30 :
Edited line 22 :
Finally, we can use the rspec matchers to make sure our views are ok.
Finally, we can use the rspec matchers to mkae sure our views are ok.
Edited line 47 :
Edited line 16 :
Edited line 30 :
Edited line 1 :
When testing a view you want to stub the controller and render its view. In a before block, start by creating an intense of the controller that will render your view:
@controller = Posts.new(fake_request)
Posts being the name of my controller
fake_request is a helper (TODO: explain more)
Next we need to assign some values to pass to the view:
@controller.assigns[:posts] = [Post.new(:id => 1, :body => "Merb!")]
In this example we are creating a controller instance variable called @posts, it’s an array containing one instance of the Post object with 2 attributes set: id and body.
Finally, we can use the rspec matchers to mkae sure our views are ok.