From da4e98ed6767164d120ec57f88eabcc09f0844bb Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Tue, 22 Nov 2011 17:58:15 -0500 Subject: [PATCH 1/2] initial tests for DRYML using Cucumber and Aruba --- .gitignore | 1 + dryml/Gemfile | 6 + dryml/dryml.gemspec | 2 + dryml/features/doctest_examples.feature | 135 ++++++++++++++++++ dryml/features/static_tags.feature | 35 +++++ .../step_definitions/dom_comparison.rb | 10 ++ dryml/features/step_definitions/rendering.rb | 21 +++ dryml/features/support/env.rb | 25 ++++ dryml/features/support/strip_formatter.rb | 14 ++ dryml/lib/dryml.rb | 2 +- 10 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 dryml/Gemfile create mode 100644 dryml/features/doctest_examples.feature create mode 100644 dryml/features/static_tags.feature create mode 100644 dryml/features/step_definitions/dom_comparison.rb create mode 100644 dryml/features/step_definitions/rendering.rb create mode 100644 dryml/features/support/env.rb create mode 100644 dryml/features/support/strip_formatter.rb diff --git a/.gitignore b/.gitignore index 02254af12..4ba26ad47 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ hobo/taglib-docs */pkg dryml/lib/doc +dryml/tmp doc dryml/doc .yardoc diff --git a/dryml/Gemfile b/dryml/Gemfile new file mode 100644 index 000000000..0d214688b --- /dev/null +++ b/dryml/Gemfile @@ -0,0 +1,6 @@ +source "http://rubygems.org" + +gem 'hobo_support', :path => '../hobo_support' + +gemspec + diff --git a/dryml/dryml.gemspec b/dryml/dryml.gemspec index b98bd7c0a..e82ae3e40 100644 --- a/dryml/dryml.gemspec +++ b/dryml/dryml.gemspec @@ -14,6 +14,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency('actionpack', ["~> 3.1.0"]) s.add_runtime_dependency('hobo_support', ["= #{version}"]) s.add_development_dependency('rubydoctest', [">= 0"]) + s.add_development_dependency('cucumber', '~> 1.1.0') + s.add_development_dependency('aruba', '~> 0.4.6') s.files = `git ls-files -x #{name}/* -z`.split("\0") diff --git a/dryml/features/doctest_examples.feature b/dryml/features/doctest_examples.feature new file mode 100644 index 000000000..14d159b0a --- /dev/null +++ b/dryml/features/doctest_examples.feature @@ -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: + """ + + Hi + + + Bye + + """ + When I render "doctest.dryml" + Then the output DOM should be: + """ + Hi + """ + + Scenario: repeating tags + Given a file named "doctest.dryml" with: + """ + + <%= this %> + + """ + When I render "doctest.dryml" + Then the output DOM should be: + """ + 1 + 2 + 3 + """ + + Scenario: defining a tag with a default parameter + Given a file named "doctest.dryml" with: + """ + +

+ + Hi + """ + When I render "doctest.dryml" + Then the output DOM should be: + """ +

+ Hi +

+ """ + + Scenario: calling a tag using call-tag + Given a file named "doctest.dryml" with: + """ + +

+ + + Hi + + """ + When I render "doctest.dryml" + Then the output DOM should be: + """ +

+ Hi +

+ """ + + Scenario: wrapping content with a custom tag + Given a file named "doctest.dryml" with: + """ + +

+ + + img + + """ + When I render "doctest.dryml" + Then the output DOM should be: + """ +

+ img +

+ """ + + Scenario: extending a tag + Given a file named "doctest_taglib.dryml" with: + """ + +

+ + """ + And a file named "doctest_extend.dryml" with: + """ + + + Hello + + + """ + And a file named "doctest.dryml" with: + """ + New World + """ + 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: + """ +

Hello New World

+ """ + diff --git a/dryml/features/static_tags.feature b/dryml/features/static_tags.feature new file mode 100644 index 000000000..516d5c071 --- /dev/null +++ b/dryml/features/static_tags.feature @@ -0,0 +1,35 @@ +Feature: Static tags render correctly + + Scenario: Static tag with static attributes + + Given a file named "static_tag.dryml" with: + """ +
+ FOO +
+ """ + When I render "static_tag.dryml" + Then the output DOM should be: + """ +
+ FOO +
+ """ + + Scenario: Static tag with an interpolated attribute + + Given a file named "static_tag.dryml" with: + """ + <% some_var = 'foo' %> +
+ FOO +
+ """ + When I render "static_tag.dryml" + Then the output DOM should be: + """ +
+ FOO +
+ """ + diff --git a/dryml/features/step_definitions/dom_comparison.rb b/dryml/features/step_definitions/dom_comparison.rb new file mode 100644 index 000000000..dbb57f801 --- /dev/null +++ b/dryml/features/step_definitions/dom_comparison.rb @@ -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("#{expected_html}"), expected_rendered) + formatter.write(REXML::Document.new("#{@rendered_dom}"), actual_rendered) + actual_rendered.should eq(expected_rendered) +end + diff --git a/dryml/features/step_definitions/rendering.rb b/dryml/features/step_definitions/rendering.rb new file mode 100644 index 000000000..02f6bf4f7 --- /dev/null +++ b/dryml/features/step_definitions/rendering.rb @@ -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 + diff --git a/dryml/features/support/env.rb b/dryml/features/support/env.rb new file mode 100644 index 000000000..25c304239 --- /dev/null +++ b/dryml/features/support/env.rb @@ -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 + diff --git a/dryml/features/support/strip_formatter.rb b/dryml/features/support/strip_formatter.rb new file mode 100644 index 000000000..3734c1321 --- /dev/null +++ b/dryml/features/support/strip_formatter.rb @@ -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 diff --git a/dryml/lib/dryml.rb b/dryml/lib/dryml.rb index d53cce110..3ab0e3372 100644 --- a/dryml/lib/dryml.rb +++ b/dryml/lib/dryml.rb @@ -175,7 +175,7 @@ def render(template_src, locals={}, template_path=nil, included_taglibs=[], view this = locals.delete(:this) || nil renderer_class = Dryml::Template.build_cache[template_path]._?.environment || - make_renderer_class(template_src, template_path, locals.keys) + make_renderer_class(template_src, template_path, locals.keys, included_taglibs) renderer_class.new(view).render_page(this, locals) end From 56c39fb2d584e4c11ff5fc0149f9bdc79b48fdfc Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Tue, 22 Nov 2011 17:59:15 -0500 Subject: [PATCH 2/2] Revert "initial tests for DRYML using Cucumber and Aruba" This reverts commit da4e98ed6767164d120ec57f88eabcc09f0844bb. --- .gitignore | 1 - dryml/Gemfile | 6 - dryml/dryml.gemspec | 2 - dryml/features/doctest_examples.feature | 135 ------------------ dryml/features/static_tags.feature | 35 ----- .../step_definitions/dom_comparison.rb | 10 -- dryml/features/step_definitions/rendering.rb | 21 --- dryml/features/support/env.rb | 25 ---- dryml/features/support/strip_formatter.rb | 14 -- dryml/lib/dryml.rb | 2 +- 10 files changed, 1 insertion(+), 250 deletions(-) delete mode 100644 dryml/Gemfile delete mode 100644 dryml/features/doctest_examples.feature delete mode 100644 dryml/features/static_tags.feature delete mode 100644 dryml/features/step_definitions/dom_comparison.rb delete mode 100644 dryml/features/step_definitions/rendering.rb delete mode 100644 dryml/features/support/env.rb delete mode 100644 dryml/features/support/strip_formatter.rb diff --git a/.gitignore b/.gitignore index 4ba26ad47..02254af12 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ hobo/taglib-docs */pkg dryml/lib/doc -dryml/tmp doc dryml/doc .yardoc diff --git a/dryml/Gemfile b/dryml/Gemfile deleted file mode 100644 index 0d214688b..000000000 --- a/dryml/Gemfile +++ /dev/null @@ -1,6 +0,0 @@ -source "http://rubygems.org" - -gem 'hobo_support', :path => '../hobo_support' - -gemspec - diff --git a/dryml/dryml.gemspec b/dryml/dryml.gemspec index e82ae3e40..b98bd7c0a 100644 --- a/dryml/dryml.gemspec +++ b/dryml/dryml.gemspec @@ -14,8 +14,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency('actionpack', ["~> 3.1.0"]) s.add_runtime_dependency('hobo_support', ["= #{version}"]) s.add_development_dependency('rubydoctest', [">= 0"]) - s.add_development_dependency('cucumber', '~> 1.1.0') - s.add_development_dependency('aruba', '~> 0.4.6') s.files = `git ls-files -x #{name}/* -z`.split("\0") diff --git a/dryml/features/doctest_examples.feature b/dryml/features/doctest_examples.feature deleted file mode 100644 index 14d159b0a..000000000 --- a/dryml/features/doctest_examples.feature +++ /dev/null @@ -1,135 +0,0 @@ -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: - """ - - Hi - - - Bye - - """ - When I render "doctest.dryml" - Then the output DOM should be: - """ - Hi - """ - - Scenario: repeating tags - Given a file named "doctest.dryml" with: - """ - - <%= this %> - - """ - When I render "doctest.dryml" - Then the output DOM should be: - """ - 1 - 2 - 3 - """ - - Scenario: defining a tag with a default parameter - Given a file named "doctest.dryml" with: - """ - -

- - Hi - """ - When I render "doctest.dryml" - Then the output DOM should be: - """ -

- Hi -

- """ - - Scenario: calling a tag using call-tag - Given a file named "doctest.dryml" with: - """ - -

- - - Hi - - """ - When I render "doctest.dryml" - Then the output DOM should be: - """ -

- Hi -

- """ - - Scenario: wrapping content with a custom tag - Given a file named "doctest.dryml" with: - """ - -

- - - img - - """ - When I render "doctest.dryml" - Then the output DOM should be: - """ -

- img -

- """ - - Scenario: extending a tag - Given a file named "doctest_taglib.dryml" with: - """ - -

- - """ - And a file named "doctest_extend.dryml" with: - """ - - - Hello - - - """ - And a file named "doctest.dryml" with: - """ - New World - """ - 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: - """ -

Hello New World

- """ - diff --git a/dryml/features/static_tags.feature b/dryml/features/static_tags.feature deleted file mode 100644 index 516d5c071..000000000 --- a/dryml/features/static_tags.feature +++ /dev/null @@ -1,35 +0,0 @@ -Feature: Static tags render correctly - - Scenario: Static tag with static attributes - - Given a file named "static_tag.dryml" with: - """ -
- FOO -
- """ - When I render "static_tag.dryml" - Then the output DOM should be: - """ -
- FOO -
- """ - - Scenario: Static tag with an interpolated attribute - - Given a file named "static_tag.dryml" with: - """ - <% some_var = 'foo' %> -
- FOO -
- """ - When I render "static_tag.dryml" - Then the output DOM should be: - """ -
- FOO -
- """ - diff --git a/dryml/features/step_definitions/dom_comparison.rb b/dryml/features/step_definitions/dom_comparison.rb deleted file mode 100644 index dbb57f801..000000000 --- a/dryml/features/step_definitions/dom_comparison.rb +++ /dev/null @@ -1,10 +0,0 @@ -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("#{expected_html}"), expected_rendered) - formatter.write(REXML::Document.new("#{@rendered_dom}"), actual_rendered) - actual_rendered.should eq(expected_rendered) -end - diff --git a/dryml/features/step_definitions/rendering.rb b/dryml/features/step_definitions/rendering.rb deleted file mode 100644 index 02f6bf4f7..000000000 --- a/dryml/features/step_definitions/rendering.rb +++ /dev/null @@ -1,21 +0,0 @@ -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 - diff --git a/dryml/features/support/env.rb b/dryml/features/support/env.rb deleted file mode 100644 index 25c304239..000000000 --- a/dryml/features/support/env.rb +++ /dev/null @@ -1,25 +0,0 @@ -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 - diff --git a/dryml/features/support/strip_formatter.rb b/dryml/features/support/strip_formatter.rb deleted file mode 100644 index 3734c1321..000000000 --- a/dryml/features/support/strip_formatter.rb +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/dryml/lib/dryml.rb b/dryml/lib/dryml.rb index 3ab0e3372..d53cce110 100644 --- a/dryml/lib/dryml.rb +++ b/dryml/lib/dryml.rb @@ -175,7 +175,7 @@ def render(template_src, locals={}, template_path=nil, included_taglibs=[], view this = locals.delete(:this) || nil renderer_class = Dryml::Template.build_cache[template_path]._?.environment || - make_renderer_class(template_src, template_path, locals.keys, included_taglibs) + make_renderer_class(template_src, template_path, locals.keys) renderer_class.new(view).render_page(this, locals) end