require 'test_helper' class InteractionTest < Test::Unit::TestCase include Less setup do unless defined?(TestInteraction) class TestInteraction < Less::Interaction def run end end end end teardown do self.class.send(:remove_const, :TestInteraction) end should "not be able to run an interaction without run defined" do class InteractionWithoutRun < Interaction; end assert_raise(InvalidInteractionError) { InteractionWithoutRun.run } end should "not be able to run an interaction with something that isn't an options hash" do assert_raise(InvalidInteractionError) { TestInteraction.run('a') } end should "be able to run an interaction with run defined" do assert_nothing_raised { TestInteraction.run } end should "run an interaction with an options hash" do assert_nothing_raised { TestInteraction.run(:test => 3) } end should "call the run instance method when running an interaction" do TestInteraction.any_instance.expects(:run) TestInteraction.run end should "fail if an expected parameter is not found" do TestInteraction.expects(:title) assert_raise(MissingParameterError) { TestInteraction.run } end should "fail if an expected parameter is nil" do TestInteraction.expects(:title) assert_raise(MissingParameterError) { TestInteraction.run(:title => nil) } end should "run if an expected parameter is found" do TestInteraction.expects(:title) assert_nothing_raised { TestInteraction.run(:title => "Hello, test") } end should "run if an expected parameter is found, even if it is nil, if the option is specified" do TestInteraction.expects(:title, :allow_nil => true) assert_nothing_raised { TestInteraction.run(:title => nil) } end end