# W/ fixtures, ERB gives $end unexpected. Options?

**URL:** <https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572>\
**Category:** Rails\
**Created:** [July 27, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572 "2007-07-27T17:45:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 27, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572/1 "2007-07-27T17:45:15Z")

</div>

With my fixtures, I am getting:  
Fixture::FormatError: a YAML error occurred parsing  
/home/hgs/aeg\_intranet/csest  
ore/config/…/test/fixtures/loans.yml. Please note that YAML must be  
consistentl  
y indented using spaces. Tabs are not allowed. Please have a look at  
[http://www](http://www).  
[YAML Ain't Markup Language](http://yaml.org/faq.html)  
The exact error was:  
SyntaxError: compile error  
(erb):65: syntax error, unexpected $end, expecting ‘)’  
\_erbout  
^  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/fixtures.r  
b:308:in `read\_fixture\_files’

Now there are no unmatched parentheses in the one file, but I’m  
using fixture\_references to make calls to pull info from other  
files. I recognize this $end type message as coming from ruby  
itself, rather than ERB or rails. I get this running erb on the  
files manually, but if I print the output of the script out with  
erb -x then there are no such parenthetical errors.

Since this is an apparently missing close bracket, it will be  
difficult to get any parser to tell me where the corresponding  
opening bracket is. The position of every last parenthesis is not  
pushed onto the stack, at least not in normal operation, I imagine.  
I’ve not tried any other implementations of Ruby for anything  
(JRuby, Rubinius) so I don’t know if is easier to trap this kind of  
information in those, but failing that, are there any tools to  
assist in tracking this kind of thing down? Maybe there’s something  
I can interpose to ensure that the strings I get back from the calls  
to methods have balanced brackets?

I may be able to use Lua’s “%b()” to hunt this bug, but its a while  
since  
I’ve touched Lua.

```
    Thank you,
    Hugh

```

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 27, 2007, 8:03pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572/2 "2007-07-27T20:03:31Z")

</div>

I think the error is telling you there is an extra ‘end’ keyword  
before the closing parenthesis. Make sure that all 'end’s have  
matching block starting keywords.

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 27, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572/3 "2007-07-27T20:04:32Z")

</div>

On Fri, 27 Jul 2007, Hugh S. wrote:

> With my fixtures, I am getting:  
> Fixture::FormatError: a YAML error occurred parsing /home/hgs/aeg\_intranet/csest  
> […]  
> The exact error was:  
> SyntaxError: compile error  
> (erb):65: syntax error, unexpected $end, expecting ‘)’  
> \_erbout  
> […]  
> I may be able to use Lua’s “%b()” to hunt this bug, but its a while since  
> I’ve touched Lua.

OK, I used lua’s gsub:

text = io.read("\*a")  
result = string.gsub(text, “%b()”, “”)  
print(result)

and the result (checked with grep, fgrep and visually) had no spare  
parentheses for any of the yaml files piped through this.

> ```
> Thank you,
> Hugh
> 
> ```

```
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 30, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572/4 "2007-07-30T13:53:32Z")

</div>

On Fri, 27 Jul 2007, Hugh S. wrote:

> On Fri, 27 Jul 2007, Nick wrote:
> 
> > I think the error is telling you there is an extra ‘end’ keyword  
> > before the closing parenthesis. Make sure that all 'end’s have
> 
> Oh, I thought $end meant end of the file and that kend or Kend meant  
> an end keyword. Thank you. I’ll have a look at that.

I think I have found out what this is due to. So for the benefit of  
anyone still reading this thread and the archives:

I had a fixture, using fixture\_references, of the form (not copied  
and pasted):

loan\_should\_work:  
id: \<%= id += 1 %\>  
device\_id: \<%= devices(:still\_camera1, ‘id’); # expected to be 4 %\>  
student\_id: \<%= students(:fred\_bloggs, ‘id’); # expected to be 6 %\>  
[…]

The comments inside the \<%=…%\> don’t actually work. Trailing  
comments (after \<%=…%\>) don’t work out right, and it seems they  
are not legal in YAML. The only comments legal in YAML, AFAICS, are  
those beginning in column 1. This is a shame because it would be  
good to add supporting information to my data. I wish there had  
been a better diagnostic message complaining about comments, but  
since I, myself, find parsers difficult to write, I am not in a  
position to be harsh with my criticism :-). Maybe someone better at  
this than me can fix this? Maybe I have misdiagnosed the problem,  
even though this now seems to work?

Anyway, in the hope it helps someone else…

```
    Thank you,
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Hugh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/d2c977/32.png) [@Hugh\_S](https://www.ruby-forum.com/u/Hugh_S)\
**Post date:** [July 27, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/w-fixtures-erb-gives-end-unexpected-options/110572/5 "2007-07-27T20:06:32Z")

</div>

On Fri, 27 Jul 2007, Nick wrote:

> I think the error is telling you there is an extra ‘end’ keyword  
> before the closing parenthesis. Make sure that all 'end’s have

Oh, I thought $end meant end of the file and that kend or Kend meant  
an end keyword. Thank you. I’ll have a look at that.

> matching block starting keywords.

```
    Hugh
```
