开发者

Annoying RSPEC Error

开发者 https://www.devze.com 2023-03-03 05:36 出处:网络
Hey all, My Rspec test fail with the error: syntax error, unexpected kEND, expecting $end (SyntaxError)

Hey all, My Rspec test fail with the error:

syntax error, unexpected kEND, expecting $end (SyntaxError)

I don't know why, my code is as follows (actual content removed via the arrows on the sidebar in xcode):

require 'spec_helper'

describe UsersController do 
  render_views 
  describe "GET 'show'" do 
    ... 
  end 
  describe "GET 'new'" do 
     ... 
  end 
  describe "PO开发者_StackOverflow社区ST 'create'" do 
    ... 
  end 
end 

Full code at http://snipt.org/xtpm


In the source link you posted, a lot of your blocks are using DO instead of do. This will definitely cause the issue you are describing.


Usually that error indicates you've got an extra end somewhere in your program. You should check that everything is balanced correctly in the file that generated the error. One way to do this is to cut out large chunks and see if you can simply "run" the file by itself until you narrow it down to the precise spot.

As a note, if you make a disciplined effort to maintain consistent indentation then these sorts of errors will be more evident. From the look of things, perhaps due to the pasting and conversion of tabs, the blocks are all over the place.

In any case, the pasted code does at least pass through the parser without incident.


Normally what this error means is that you have an end too little, it encountered the end of the file, and was expecting to still find an end command. However, from the code you showed that was not directly clear to me. Your indentation was awfully inconsistent, that didn't help to make it clear at first sight :)

What i did see: if you are using rspec1, the documentation recommends using {} instead of do .. end when testing for change. So in your case:

lambda {
  post :create, :user => @attr
}.should change(User, :count).by(1)

In rspec2, you should write

expect { ... }.to change

so in your case

expect { post :create, :user => @attr }.to change(User, :count).by(1)

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消