August 29, 2007

Argible: testing argible-ized actions

Last week Jay Fields and I were discussing Argible and he asked, "How's testing an action that uses Argible?", the answer ... easy.

Suppose we have the following Controller with an argible-ized action:

class CalculatorController < ApplicationController

argible(:first => :to_i, :second => :to_i)
def add(first, second)
@result = first + second
end

end

And here is the associated RSpec test:

describe CalculatorController, "add action" do
controller_name :calculator

it "should add argument values" do
post :add, :first => "18", :second => "2"
controller.instance_variable_get(:@result).should == 20
end

end

You can see from the test that you do not need to do anything special to test your argible annotated action methods. Just call the action with whatever parameter name and values your action requires.

1 comment:

Peter Ryan said...

argibley.RSpec.tacular