erector 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+ require 'benchmark'
3
+
4
+ module MixinSpec
5
+ class Thing
6
+ include Erector::Mixin
7
+ end
8
+
9
+ describe Erector::Mixin do
10
+ describe "#erector" do
11
+ it "renders its block to a string" do
12
+
13
+ class MixinSpec::Thing
14
+ def name
15
+ erector do
16
+ span :class => "name" do
17
+ text "Gabriel "
18
+ i "Garcia"
19
+ text " Marquez"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Thing.new.name.should == "<span class=\"name\">Gabriel <i>Garcia</i> Marquez</span>"
26
+ end
27
+
28
+ it "passes its parameters to to_s" do
29
+ class MixinSpec::Thing
30
+ def pretty_name
31
+ erector(:prettyprint => true) do
32
+ div :class => "name" do
33
+ ul do
34
+ li "Gabriel"
35
+ li "Garcia"
36
+ li "Marquez"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ Thing.new.pretty_name.should ==
44
+ "<div class=\"name\">\n" +
45
+ " <ul>\n" +
46
+ " <li>Gabriel</li>\n" +
47
+ " <li>Garcia</li>\n" +
48
+ " <li>Marquez</li>\n" +
49
+ " </ul>\n" +
50
+ "</div>\n"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,4 +1,5 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+ require 'benchmark'
2
3
 
3
4
  module WidgetSpec
4
5
  describe Erector::Widget do
@@ -51,6 +52,36 @@ module WidgetSpec
51
52
  end
52
53
  end
53
54
 
55
+ describe "#to_a" do
56
+ it "returns an array" do
57
+ widget = Erector::Widget.new do
58
+ div "Hello"
59
+ end
60
+ widget.to_a.should == ["<div>", "Hello", "</div>"]
61
+ end
62
+
63
+ # removing this, since oddly, when i run this test solo it works, but when
64
+ # i run it as part of a rake suite, i get the opposite result -Alex
65
+ # it "runs faster than using a string as the output" do
66
+ # widget = Erector::Widget.new do
67
+ # 1000.times do |i|
68
+ # div "Lorem ipsum dolor sit amet #{i}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est #{i} laborum."
69
+ # end
70
+ # end
71
+ #
72
+ # times = 20
73
+ # time_for_to_a = Benchmark.measure { times.times { widget.to_a } }.total
74
+ # # puts "to_a: #{time_for_to_a}"
75
+ # time_for_string = Benchmark.measure { times.times { widget.to_s(:output => "") } }.total
76
+ # # puts "to_s(''): #{time_for_string}"
77
+ #
78
+ # percent_faster = (((time_for_string - time_for_to_a) / time_for_string)*100)
79
+ # # puts ("%.1f%%" % percent_faster)
80
+ #
81
+ # (time_for_to_a <= time_for_string).should be_true
82
+ # end
83
+ # end
84
+
54
85
  describe "#instruct" do
55
86
  it "when passed no arguments; returns an XML declaration with version 1 and utf-8" do
56
87
  html = Erector::Widget.new do
@@ -786,5 +817,12 @@ module WidgetSpec
786
817
  end
787
818
 
788
819
  end
820
+
821
+ describe "#close_tag" do
822
+ it "works when it's all alone, even though it messes with the indent level" do
823
+ Erector::Widget.new { close_tag :foo }.to_s.should == "</foo>"
824
+ Erector::Widget.new { close_tag :foo; close_tag :bar }.to_s.should == "</foo></bar>"
825
+ end
826
+ end
789
827
  end
790
828
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-06 00:00:00 -07:00
12
+ date: 2009-05-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,7 @@ files:
35
35
  - lib/erector/erected.rb
36
36
  - lib/erector/extensions/object.rb
37
37
  - lib/erector/indenting.rb
38
+ - lib/erector/mixin.rb
38
39
  - lib/erector/rails/extensions/action_controller.rb
39
40
  - lib/erector/rails/extensions/action_view.rb
40
41
  - lib/erector/rails/extensions/rails_widget/helpers.rb
@@ -55,7 +56,12 @@ files:
55
56
  - VERSION.yml
56
57
  - bin/erector
57
58
  - spec/core_spec_suite.rb
59
+ - spec/erect/erect_rails_spec.rb
60
+ - spec/erect/erect_spec.rb
61
+ - spec/erect/erected_spec.rb
62
+ - spec/erect/rhtml_parser_spec.rb
58
63
  - spec/erector/indentation_spec.rb
64
+ - spec/erector/mixin_spec.rb
59
65
  - spec/erector/unicode_builder_spec.rb
60
66
  - spec/erector/widget_spec.rb
61
67
  - spec/erector/widgets/table_spec.rb