spec/macros4cuke/templating/engine_spec.rb in macros4cuke-0.3.00 vs spec/macros4cuke/templating/engine_spec.rb in macros4cuke-0.3.01
- old
+ new
@@ -25,14 +25,15 @@
# Template containing two conditional sections
let(:sophisticated_template) do
source = <<-SNIPPET
When I fill in "firstname" with "<firstname>"
And I fill in "lastname" with "<lastname>"
- <?address>And I fill in "address" with "<address>"</address>
+<?address> And I fill in "address" with "<address>"</address>
<?birthdate>
And I fill in "birthdate" with "<birthdate>"
</birthdate>
+<?dummy></dummy>
And I click "Register"
SNIPPET
end
@@ -199,10 +200,33 @@
text_w_empty_arg = sample_template.sub(/userid/, 'user%id')
error_message = "The invalid sign '%' occurs in the argument/tag 'user%id'."
lambda { Engine.new text_w_empty_arg }.should raise_error(Macros4Cuke::InvalidCharError, error_message)
end
+ it "should complain when a section has no closing tag" do
+ # Removing an end of section tag...
+ text_w_open_section = sophisticated_template.sub(/<\/address>/, '')
+
+ error_message = "Unterminated section <?address>."
+ lambda { Engine.new text_w_open_section}.should raise_error(StandardError, error_message)
+ end
+
+ it "should complain when a closing tag does not correspond to currently open section" do
+ # Replacing an end of section tag by another...
+ text_w_wrong_end = sophisticated_template.sub(/<\/address>/, '</foobar>')
+
+ error_message = "End of section</foobar> doesn't match current section 'address'."
+ lambda { Engine.new text_w_wrong_end}.should raise_error(StandardError, error_message)
+ end
+
+ it "should complain when a closing tag is found while no section is open" do
+ # Replacing an end of section tag by another...
+ text_w_wrong_end = sophisticated_template.sub(/<\?birthdate>/, '</foobar>')
+ error_message = "End of section</foobar> found while no corresponding section is open."
+ lambda { Engine.new text_w_wrong_end}.should raise_error(StandardError, error_message)
+ end
+
end # context
context "Provided services" do
it "should know the variable(s) it contains" do
@@ -281,18 +305,28 @@
}
rendered_text = instance.render(Object.new, locals)
expected = <<-SNIPPET
When I fill in "firstname" with "Anon"
And I fill in "lastname" with "Eemoos"
-
-
And I fill in "birthdate" with "1976-04-21"
-
And I click "Register"
SNIPPET
rendered_text.should == expected
+ # Redo with another context
+ locals["birthdate"] = nil
+ locals["address"] = "122, Mercer Street"
+
+ rendered_text = instance.render(Object.new, locals)
+ expected = <<-SNIPPET
+ When I fill in "firstname" with "Anon"
+ And I fill in "lastname" with "Eemoos"
+ And I fill in "address" with "122, Mercer Street"
+ And I click "Register"
+SNIPPET
+
+ rendered_text.should == expected
end
it "should render multivalued actuals" do
locals = {'userid' => ["johndoe", "yeti"] } # Silly case
\ No newline at end of file