spec/macros4cuke/templating/engine_spec.rb in macros4cuke-0.2.22 vs spec/macros4cuke/templating/engine_spec.rb in macros4cuke-0.3.00
- old
+ new
@@ -9,19 +9,35 @@
module Templating # Open this namespace to get rid of module qualifier prefixes
describe Engine do
+ # Sample template (consisting of a sequence of steps)
let(:sample_template) do
source = <<-SNIPPET
Given I landed in the homepage
# The credentials are entered here
And I fill in "Username" with "<userid>"
And I fill in "Password" with "<password>"
And I click "Sign in"
SNIPPET
end
+
+ # 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>
+ <?birthdate>
+ And I fill in "birthdate" with "<birthdate>"
+ </birthdate>
+ And I click "Register"
+SNIPPET
+ end
+
+
# Rule for default instantiation
subject { Engine.new sample_template }
@@ -165,10 +181,15 @@
# Case of an empty template
instance = Engine.new ''
instance.source.should be_empty
end
+
+ it "should accept conditional section" do
+ lambda { Engine.new sophisticated_template }.should_not raise_error
+ instance = Engine.new sophisticated_template
+ end
it "should complain when a placeholder is empty or blank" do
text_w_empty_arg = sample_template.sub(/userid/, '')
error_message = %Q|An empty or blank argument occurred in 'And I fill in "Username" with "<>"'.|
lambda { Engine.new text_w_empty_arg }.should raise_error(Macros4Cuke::EmptyArgumentError, error_message)
@@ -177,10 +198,11 @@
it "should complain when a placeholder contains an invalid character" do
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
+
end # context
context "Provided services" do
it "should know the variable(s) it contains" do
@@ -246,9 +268,33 @@
# Case of an empty source template text
instance = Engine.new ''
instance.render(nil, {}).should be_empty
end
+
+
+ it "should render conditional sections" do
+ instance = Engine.new(sophisticated_template)
+
+ locals = {'firstname' => "Anon",
+ "lastname" => "Eemoos" ,
+ "birthdate" => "1976-04-21"
+ }
+ 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
+
+ end
+
it "should render multivalued actuals" do
locals = {'userid' => ["johndoe", "yeti"] } # Silly case
rendered_text = subject.render(Object.new, locals)
\ No newline at end of file