On May 26, 2011, at 11:51 AM, Peter Bell wrote: > Hi All, > > New to rspec. Done some Rails, done TDD in other languages, trying to get the > two to meet. Getting a syntax error on my first routing spec: > > context "public routing" do > it "routes / to public#landing" do > { :get => "/" }.should route_to{:controller => "public", :action => > "landing"} > end > end > > I run: rspec spec/ > > I get: > /rspec/core/configuration.rb:419:in `load': > /Users/peterbell/Sites/rails/skinnio-web/spec/routing/public_spec.rb:6: > syntax error, unexpected tASSOC, expecting '}' (SyntaxError) > ....should route_to{:controller => "public", :action => "landin... > ... ^ > /Users/peterbell/Sites/rails/skinnio-web/spec/routing/public_spec.rb:6: > syntax error, unexpected ',', expecting '}' > > Looks like it's expecting just a single argument to route_to, but I see > examples all over the place with two arguments. I'm running Rails 3.1rc1 and > just updates rspec to 2.6.1 this morning. > > Any thoughts much appreciated!
This is just a matter of getting accustomed to Ruby syntax. The goal here is to submit a hash as an argument to the route_to method. Here's the most explicit way to do it: { :get => "/" }.should route_to({:controller => "public", :action => "landing"}) The following will also work, because Ruby will interpret key/value pairs at the end of argument as a hash: { :get => "/" }.should route_to(:controller => "public", :action => "landing") But this won't: { :get => "/" }.should route_to{:controller => "public", :action => "landing"} The reason is that, in this last form, Ruby thinks you're passing a block to the route_to method, not a Hash. HTH, David _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users