-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial tests for DRYML using Cucumber and Aruba
- Loading branch information
Showing
10 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ hobo/taglib-docs | |
*/pkg | ||
|
||
dryml/lib/doc | ||
dryml/tmp | ||
doc | ||
dryml/doc | ||
.yardoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
gem 'hobo_support', :path => '../hobo_support' | ||
|
||
gemspec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
Feature: Doctest examples | ||
|
||
Scenario: plain text | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
hi | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
hi | ||
""" | ||
|
||
Scenario: single ERB output tag | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<%= this %> | ||
""" | ||
And the local variable "this" has the value "hello" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
hello | ||
""" | ||
|
||
Scenario: if-else | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<if test="&true"> | ||
Hi | ||
</if> | ||
<else> | ||
Bye | ||
</else> | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
Hi | ||
""" | ||
|
||
Scenario: repeating tags | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<repeat with="&[1,2,3]"> | ||
<span><%= this %></span> | ||
</repeat> | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<span>1</span> | ||
<span>2</span> | ||
<span>3</span> | ||
""" | ||
|
||
Scenario: defining a tag with a default parameter | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<def tag="myp"> | ||
<p param="default"/> | ||
</def> | ||
<myp>Hi</myp> | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<p> | ||
Hi | ||
</p> | ||
""" | ||
|
||
Scenario: calling a tag using call-tag | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<def tag="myp"> | ||
<p param="default" /> | ||
</def> | ||
<call-tag tag="myp"> | ||
Hi | ||
</call-tag> | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<p> | ||
Hi | ||
</p> | ||
""" | ||
|
||
Scenario: wrapping content with a custom tag | ||
Given a file named "doctest.dryml" with: | ||
""" | ||
<def tag="myp"> | ||
<p param="default" /> | ||
</def> | ||
<wrap tag="myp" when="&true"> | ||
img | ||
</wrap> | ||
""" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<p> | ||
img | ||
</p> | ||
""" | ||
|
||
Scenario: extending a tag | ||
Given a file named "doctest_taglib.dryml" with: | ||
""" | ||
<def tag="myp"> | ||
<p param="default" /> | ||
</def> | ||
""" | ||
And a file named "doctest_extend.dryml" with: | ||
""" | ||
<extend tag="myp"> | ||
<old-myp merge> | ||
<default: replace>Hello <default restore /></default:> | ||
</old-myp> | ||
</extend> | ||
""" | ||
And a file named "doctest.dryml" with: | ||
""" | ||
<myp>New World</myp> | ||
""" | ||
When I include the taglib "doctest_taglib" | ||
And I include the taglib "doctest_extend" | ||
When I render "doctest.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<p>Hello New World</p> | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Static tags render correctly | ||
|
||
Scenario: Static tag with static attributes | ||
|
||
Given a file named "static_tag.dryml" with: | ||
""" | ||
<div class="foo"> | ||
FOO | ||
</div> | ||
""" | ||
When I render "static_tag.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<div class="foo"> | ||
FOO | ||
</div> | ||
""" | ||
|
||
Scenario: Static tag with an interpolated attribute | ||
|
||
Given a file named "static_tag.dryml" with: | ||
""" | ||
<% some_var = 'foo' %> | ||
<div class="#{some_var}"> | ||
FOO | ||
</div> | ||
""" | ||
When I render "static_tag.dryml" | ||
Then the output DOM should be: | ||
""" | ||
<div class="foo"> | ||
FOO | ||
</div> | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Then /^the output DOM should be:$/ do |expected_html| | ||
expected_rendered = '' | ||
actual_rendered = '' | ||
formatter = StripFormatter.new | ||
# wrap in html tag, as REXML gets grumpy if there's more than one root node | ||
formatter.write(REXML::Document.new("<html>#{expected_html}</html>"), expected_rendered) | ||
formatter.write(REXML::Document.new("<html>#{@rendered_dom}</html>"), actual_rendered) | ||
actual_rendered.should eq(expected_rendered) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
When /^I render "([^"]*)"$/ do |file| | ||
file_path = aruba_path(file) | ||
file_data = File.read(file_path) | ||
@locals ||= {} | ||
@taglibs ||= [] | ||
@rendered_dom = Dryml.render(file_data, @locals, file_path, @taglibs) | ||
Dryml::Template.clear_build_cache | ||
end | ||
|
||
When /^I include the taglib "([^"]*)"$/ do |file| | ||
file_path = aruba_path(file+".dryml") | ||
template_dir = File.dirname(file_path) | ||
@taglibs ||= [] | ||
@taglibs << { :src => file, :absolute_template_path => template_dir } | ||
end | ||
|
||
Given /^the local variable "([^"]*)" has the value "([^"]*)"$/ do |var, value| | ||
@locals ||= {} | ||
@locals[var.to_sym] = value | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
lib = File.expand_path('../../../lib', __FILE__) | ||
$:.unshift lib unless $:.include?(lib) | ||
|
||
require 'bundler' | ||
Bundler.setup | ||
require 'aruba/cucumber' | ||
|
||
require 'active_support' | ||
require 'action_view' | ||
require 'action_controller' | ||
|
||
require 'dryml' | ||
require 'dryml/railtie/template_handler' | ||
|
||
def aruba_path(file_or_dir) | ||
File.expand_path("../../../tmp/aruba/#{file_or_dir}", __FILE__) | ||
end | ||
|
||
# stub this | ||
module Hobo | ||
def self.root | ||
'no_such_path' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rexml/document' | ||
require 'rexml/formatters/default' | ||
|
||
# strip whitespace when formatting XML | ||
|
||
class StripFormatter < REXML::Formatters::Default | ||
|
||
protected | ||
|
||
def write_text(node, output) | ||
output << node.to_s.strip | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207429d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still dislike Cucumber, but I must admit that Aruba is pretty cool. Thanks, Matt.
207429d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aruba came to mind mostly for avoiding the "can't extend tags in view files" problem; taglibs seem to be really firmly rooted in the filesystem.
One note: the last test in doctest_examples doesn't pass. The default param replace doesn't do anything. I've tried with other param names and it doesn't work the same way as it does in live DRYML, so there's also a test env issue there. More updates as I keep digging.