erector 0.6.4 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 6
4
- :patch: 4
4
+ :patch: 6
5
5
 
@@ -153,8 +153,10 @@ module Erector
153
153
 
154
154
  SPACES_PER_INDENT = 2
155
155
 
156
- attr_reader :helpers, :assigns, :block, :parent, :output, :prettyprint, :indentation
156
+ RESERVED_INSTANCE_VARS = [:helpers, :assigns, :block, :parent, :output, :prettyprint, :indentation, :at_start_of_line]
157
157
 
158
+ attr_reader *RESERVED_INSTANCE_VARS
159
+
158
160
  def initialize(assigns={}, &block)
159
161
  unless assigns.is_a? Hash
160
162
  raise "Erector's API has changed. Now you should pass only an options hash into Widget.new; the rest come in via to_s, or by using #widget."
@@ -223,8 +225,10 @@ module Erector
223
225
  end
224
226
 
225
227
  def assign_local(name, value)
228
+ raise ArgumentError, "Sorry, #{name} is a reserved variable name for Erector. Please choose a different name." if RESERVED_INSTANCE_VARS.include?(name)
226
229
  instance_variable_set("@#{name}", value)
227
230
  if any_are_needed?
231
+ raise ArgumentError, "Sorry, #{name} is a reserved method name for Erector. Please choose a different name." if respond_to?(name)
228
232
  metaclass.module_eval do
229
233
  attr_reader name
230
234
  end
@@ -268,7 +272,7 @@ module Erector
268
272
  #
269
273
  # # Options: see #to_s
270
274
  def to_a(options = {}, &blk)
271
- _render(options, &blk).to_a
275
+ _render({:output => []}.merge(options), &blk).to_a
272
276
  end
273
277
 
274
278
  def _render(options = {}, &blk)
@@ -80,7 +80,7 @@ module WidgetSpec
80
80
  #
81
81
  # (time_for_to_a <= time_for_string).should be_true
82
82
  # end
83
- # end
83
+ end
84
84
 
85
85
  describe "#instruct" do
86
86
  it "when passed no arguments; returns an XML declaration with version 1 and utf-8" do
@@ -702,6 +702,15 @@ module WidgetSpec
702
702
 
703
703
  end
704
704
 
705
+ describe "assigning local variables" do
706
+ it "attempting to overwrite a reserved instance variable raises error" do
707
+ lambda {
708
+ Erector::Widget.new(:output => "foo")
709
+ }.should raise_error(ArgumentError)
710
+ end
711
+ end
712
+
713
+
705
714
  describe "when declaring parameters with the 'needs' macro" do
706
715
  it "doesn't complain if there aren't any needs declared" do
707
716
  class Thing1 < Erector::Widget
@@ -815,6 +824,13 @@ module WidgetSpec
815
824
  thing = NeedlessThing.new(:love => "all we need")
816
825
  lambda {thing.love}.should raise_error
817
826
  end
827
+
828
+ it "complains if you attempt to 'need' a variable whose name overlaps with an existing method" do
829
+ class ThingWithOverlap < Erector::Widget
830
+ needs :text
831
+ end
832
+ lambda { ThingWithOverlap.new(:text => "alas") }.should raise_error(ArgumentError)
833
+ end
818
834
 
819
835
  end
820
836
 
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.4
4
+ version: 0.6.6
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-24 00:00:00 -07:00
12
+ date: 2009-05-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency