spec/macros4cuke/macro-step_spec.rb in macros4cuke-0.2.07 vs spec/macros4cuke/macro-step_spec.rb in macros4cuke-0.2.08

- old
+ new

@@ -8,10 +8,11 @@ module Macros4Cuke # Open the module to avoid lengthy qualified names describe MacroStep do let(:sample_phrase) { "enter my credentials as <userid>]:" } + let(:sample_template) do snippet = <<-SNIPPET Given I landed in the homepage When I click "Sign in" And I fill in "Username" with "<userid>" @@ -30,12 +31,12 @@ it "should be created with a phrase and a template" do lambda { MacroStep.new(sample_phrase, sample_template) }.should_not raise_error end - it "should know its key/name" do - subject.name.should == "enter_my_credentials_as_X_T" + it "should know its key" do + subject.key.should == "enter_my_credentials_as_X_T" end it "should know the tags(placeholders) from its phrase" do subject.phrase_args.should == %w[userid] end @@ -46,21 +47,45 @@ end # context context "Provided services" do + + let(:phrase_instance) {%Q|enter my credentials as "nobody"]:|} + it "should render the substeps" do - text = subject.expand({'userid' => 'nobody', 'password' => 'no-secret'}) + text = subject.expand(phrase_instance, [ ['password', 'no-secret'] ]) expectation = <<-SNIPPET Given I landed in the homepage When I click "Sign in" And I fill in "Username" with "nobody" And I fill in "Password" with "no-secret" And I click "Submit" SNIPPET text.should == expectation end + + it "should render steps even when one argument has no actual value" do + # Special case: password has no value... + text = subject.expand(phrase_instance, [ ]) + expectation = <<-SNIPPET + Given I landed in the homepage + When I click "Sign in" + And I fill in "Username" with "nobody" + And I fill in "Password" with "" + And I click "Submit" +SNIPPET + + text.should == expectation + end + + it "should complain when an unknown variable is used" do + # Error case: there is no macro argument called <unknown> + error_message = "Unknown macro-ste argument 'unknown'." + lambda { subject.expand(phrase_instance, [ ['unknown', 'anything'] ]) }.should raise_error(UnknownArgumentError, error_message) + end + end # context end # describe \ No newline at end of file