paulo, what you're looking for in test::unit is under integration testing.
in rspec, it's usually done with stories. controller tests/specs are
specifically for one controller. integration testing is designed to test
your app as a system rather than in units. hope that helps.

RSL

On Sat, Sep 6, 2008 at 10:39 AM, Paolo Montrasio <
[EMAIL PROTECTED]> wrote:

>
> Rodrigo Rosenfeld Rosas wrote:
> > Actually, these methods (get, post, put, delete and head) are not even
> > mentioned in the API documentation.
>
> I agree with you and I'd also like to be able to call methods of other
> controllers at the beginning. However I understood that functional tests
> are
> limited to just one controller and found another and better way to test
> multiple controllers. Let's look at an example (I'm using rspec):
>
>  # This is testing UserController
>  post :signin, "user" => { "login" => "testuser", "password" =>
> "password" }
>  response.should redirect_to(:controller => "welcome", :action =>
> "index")
>
> This leaves me at the same point where a signin failure would be, i.e. a
> redirection to the home page. I'd like to check the destination page
> with
>
>  get :controller => "welcome", :action => "index"
>  response.should have_text("<p>Welcome <strong>testuser</strong>!</p>")
>
> but that's not possible because the home page is served by another
> controller.
>
> The solution is testing the authentication in integration tests. This is
> what they are for. Just for reference, this is an rspec story for that
> (there isn't much documentation on this subject, so let's spread it a
> little)
>
>  Story "Signing in", %{ A user wants to sign in }, :type => RailsStory
> do
>
>    Scenario "A user signs in" do
>      Given "An existing user" do
>        create_test_user
>      end
>      When "signing in with the right login and password" do
>        post signin_users_url,
>          :user => { :login => "testuser", :password => "password" }
>      end
>      Then "gets redirected to the home page" do
>        response.should redirect_to(:controller => "welcome",
>                                    :action => "index")
>      end
>      And "gets welcomed by login" do
>        get "/"
>        response.should include_text("<p>Welcome
> <strong>testuser</strong>!</p>")
>      end
>    end
>  end
>
>
> By the way, the get/post methods are autogenerated. They are called by
>
> http://api.rubyonrails.com/classes/ActionController/TestProcess.html#M000588
> You can look at it inside
>
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/test_process.rb
> or the equivalent file in your installation. The method generation is a
> few lines before the "def process".
>
>
> Paolo
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to