Frederick Cheung wrote:

>>  :new    => Proc.new { get :new },
>>
>>
>> My question is: How do I get access to the #get, #post, #put, and
>> #delete methods in my Proc or lambda? Any help appreciated. :)
> 
> First off I know absolutely nothing about shoulda.

Shoulda is actually just a collection of test helpers: the #setup method 
that runs before each test, the #should that defines a test, and the 
#context that encapsulates a context, e.g.:

context "GET new" do
  context "when logged in" do
    setup do
      log_in
      get :new
    end

    should_respond_with :success

    should "do something" do
      assert something
    end
  end
end

> That said blocks
> are closures, so in particular they remember the value of self when
> they were defined so if your test looks like
> 
> class SomeTestCase < Test::Unit::TestCase
>    some_macro :new => Proc.new {...}
> end
> 
> then for that block, self is and always will be SomeTestCase. The
> easiest thing to do would be to have your setup method pass self to
> the proc and have the proc call get/post/etc... on that.

That might work. I tried a different approach, it's not quite as elegant 
but I use it this way:

should_require_login :post, :create
should_require_login :get,  :edit,  :id => Page.first.id

Take a look at the method definition here: http://pastie.org/351489 The 
first argument is the HTTP method you want to use. Second argument is 
what action to test. And the third is additional parameters you want to 
pass to the action.

It works fine, but thanks anyway, Frederick. If anyone else could find 
the #should_require_login method helpful, you are free to use it. :)
-- 
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 [email protected]
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