View Specs / Edits

3 months ago

Edited line 2 :

In a before block, start by creating an instance of the controller that will render your view:

In a before block, start by creating an intense of the controller that will render your view:

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.

3 months ago

Edited line 7 :

Posts being the name of my controller.
Posts being the name of my controller

3 months ago

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 :

end
end

3 months ago

Edited line 16 :

@controller.instance_variable_set(:@posts, [Post.new(:id => 1, :body => "Merb!")])
@controller.instance_variable_set( :@posts, [Post.new(:id => 1, :body => "Merb!")] )

3 months ago

Edited line 30 :

@controller.instance_variable_set(:@posts, [Post.new(:id => 1, :body => "Merb!")])
@controller.instance_variable_set( :@posts, [Post.new(:id => 1, :body => "Merb!")] )

3 months ago

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.

3 months ago

Edited line 16 :

@controller.instance_variable_set( :@posts, [Post.new(:id => 1, :body => "Merb!")] )
@controller.assigns[:posts] = [Post.new(:id => 1, :body => "Merb!")]

Edited line 30 :

@controller.instance_variable_set( :@posts, [Post.new(:id => 1, :body => "Merb!")] )
@controller.assigns[:posts] = [Post.new(:id => 1, :body => "Merb!")]

3 months ago

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.

 
 

3 months ago