Syntax error issue

408 views
Skip to first unread message

Robert Kim

unread,
Sep 6, 2012, 10:28:36 AM9/6/12
to laruby...@googlegroups.com
First off, it was great attending my first meetup with you all.  Definitely opened my eyes to what RoR can do.

On to my issue, as you may remember, I'm trying to work my way through the Hartl tutorial (for better or worse), and I ran across an error message having to do with syntax.  From what I can surmise, it is coming from below (Section 4.1, Listing 4.4 - "Updated tests for the Home page’s title. spec/requests/static_pages_spec.rb"):

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the h1 'Sample App'" do
      visit '/static_pages/home'
      page.should have_selector('h1', :text => 'Sample App')
    end

    it "should have the base title" do
      visit '/static_pages/home'
      page.should have_selector('title',
                        :text => "Ruby on Rails Tutorial Sample App")
    end

    it "should not have a custom page title" do
      visit '/static_pages/home'
      page.should_not have_selector('title', :text => '| Home')
    end
  end
  .
  .
  .
end

The actual error reads:
Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/static_pages_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load': /Users/robertjoonkim/rails_projects/sample_app/spec/requests/static_pages_spec.rb:24: syntax error, unexpected '.' (SyntaxError)
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

Hopefully, someone here can spot the error, or point me in the right direction if it's some other issue.

Thanks!

Robert Kim

unread,
Sep 6, 2012, 10:32:41 AM9/6/12
to laruby...@googlegroups.com
Odd. Looks like the error message is being cut off.  This might be a little better:

Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/static_pages_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load': /Users/robertjoonkim/rails_projects/sample_app/spec/requests/static_pages_spec.rb:24: syntax error, unexpected '.' (SyntaxError)
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

Jen Diamond

unread,
Sep 6, 2012, 10:43:41 AM9/6/12
to laruby...@googlegroups.com
Robert,

I have been going through that book and the best thing I found is to use the full Gemfile from the end of the book otherwise there are Gemfile errors.

Jen Diamond
323-363-0002
http://www.jendiamond.com



On Thu, Sep 6, 2012 at 7:32 AM, Robert Kim <robert...@gmail.com> wrote:
Odd. Looks like the error message is being cut off.  This might be a little better:

Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/static_pages_spec.rb
/usr/local/rvm/gbert,

Cynthia Kiser

unread,
Sep 6, 2012, 12:57:23 PM9/6/12
to laruby...@googlegroups.com
If the code below is exactly what you have in your file then the part
that is throwing the error is the vertical ... between the two
'end's. I think Michael meant that as an elipsis to show there might
be more code in that section of the file. But they are not to be
copied verbatum into your test. Change this:

end
.
.
.end

to
end
end

and you should be fine.
--
Cynthia N. Kiser
c...@ugcs.caltech.edu

Cynthia Kiser

unread,
Sep 6, 2012, 1:00:39 PM9/6/12
to laruby...@googlegroups.com
Quoting Jen Diamond <thejen...@gmail.com>:
> I have been going through that book and the best thing I found is to use
> the full Gemfile from the end of the book otherwise there are Gemfile
> errors.

Which version of the book are you going through? For a while the
default version online was for Rails 3.0 and if you were running Rails
3.2 there were some changes that would be confusing. But I would have
expected the Rails 3.2 version of the tutorial to be pretty up to date.

Robert Kim

unread,
Sep 6, 2012, 1:50:52 PM9/6/12
to laruby...@googlegroups.com
Perfect.  Thanks much, Cynthia.  

Btw, I can't tell you how absurd it is for Hartl to have written the code in that way for this section.  Ridiculous.

Will DelHagen

unread,
Sep 6, 2012, 4:58:20 PM9/6/12
to laruby...@googlegroups.com
That's a standard syntax he uses throughout the book to indicate code that exists in the file but is not relevant to the current section or was written before. You should get used to it. 

By way of teaching you to fish, this part of the error message should have taken you right to the error, which was an unexpected '.' on line 24 of static_pages_spec.rb

Users/robertjoonkim/rails_projects/sample_app/spec/requests/static_pages_spec.rb:24: syntax error, unexpected '.' (SyntaxError)

--
Sent from 415-680-4700

Rob Kim

unread,
Sep 6, 2012, 5:51:33 PM9/6/12
to laruby...@googlegroups.com, laruby...@googlegroups.com
Thanks for the advice.  

- Robert Kim

Robert Kim

unread,
Sep 6, 2012, 8:49:11 PM9/6/12
to laruby...@googlegroups.com

Hello again,

Another snag, in Section 5.3.4 this time:

Having to do with Listing 5.27, Prettier tests for the static pages, Terminal gives me this when I run the
bundle exec rspec spec/requests/static_pages_spec.rb
Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/static_pages_spec.rb
.F.F.F..F

Failures:

  1) Static pages Contact page 
     Failure/Error: it { should have_selector('title', text: full_title('Contact')) }
     NoMethodError:
       undefined method `full_title' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4:0x007fcc84b11a90>
     # ./spec/requests/static_pages_spec.rb:33:in `block (3 levels) in <top (required)>'

  2) Static pages About page 
     Failure/Error: it { should have_selector('title', text: full_title('About Us')) }
     NoMethodError:
       undefined method `full_title' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x007fcc84f465c0>
     # ./spec/requests/static_pages_spec.rb:26:in `block (3 levels) in <top (required)>'

  3) Static pages Home page 
     Failure/Error: it { should have_selector('title', text: full_title('')) }
     NoMethodError:
       undefined method `full_title' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fcc81d074b0>
     # ./spec/requests/static_pages_spec.rb:11:in `block (3 levels) in <top (required)>'

  4) Static pages Help page 
     Failure/Error: it { should have_selector('title', text: full_title('Help')) }
     NoMethodError:
       undefined method `full_title' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fcc829594e8>
     # ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'

Finished in 0.39844 seconds
9 examples, 4 failures

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:33 # Static pages Contact page 
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages About page 
rspec ./spec/requests/static_pages_spec.rb:11 # Static pages Home page 
rspec ./spec/requests/static_pages_spec.rb:19 # Static pages Help page 

Randomized with seed 14196
Any ideas?
Thanks again!

Cynthia Kiser

unread,
Sep 7, 2012, 1:17:38 AM9/7/12
to laruby...@googlegroups.com
All of those are erroring on the full_title helper. That helper was
defined in listing 5.26. I would start by double checking that you
have that code within spec/support/utilities.rb If the code is there,
then the next guess is that that file is not being automatically
included as Michael asserts it should be two paragraphs after listing
5.26. In the spec/spec_helper.rb file in one of my projects, I see the
following lines which seem to agree with that assertion.

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

You can verify it by altering {|f| require f} to
{|f| puts "sourcing #{f}"; require f }
(If that causes errors, you may need f.to_s or something like that to
see what is getting 'required')

Quoting Robert Kim <robert...@gmail.com>:
> Hello again,
>
> Another snag, in Section 5.3.4 this time:
>
> Having to do with *Listing 5.27, Prettier tests for the static pages,
> Terminal gives me this when I run the*

Jen Diamond

unread,
Sep 7, 2012, 2:05:57 AM9/7/12
to laruby...@googlegroups.com
Cynthia, 

Are you studying Michael Hartl's Ruby on Rails Tutorial now in the study group?  I am in chapter 5 of that book right now. It would be so helpful to have others working on the same problems.  eek I'm a bit stuck as I can see Robert has been. I'm going to try to work it out tomorrow and over the weekend.

Cynthia Kiser

unread,
Sep 7, 2012, 11:25:29 AM9/7/12
to laruby...@googlegroups.com
Quoting Jen Diamond <thejen...@gmail.com>:
> Are you studying Michael Hartl's Ruby on Rails Tutorial now in the study
> group? I am in chapter 5 of that book right now. It would be so helpful to
> have others working on the same problems. eek I'm a bit stuck as I can see
> Robert has been. I'm going to try to work it out tomorrow and over the
> weekend.

We are not explicitly going through Rails Tutorial but last week we
were between 'books' and had a bunch of new folks who were interested
in an introduction to rails, so we dipped into it for our one hour
tour. Rob said he was having few problems with some of the exercises
and we encouraged him to post here to get some help. I hope you will
do the same if you run into more problems when you get back to your
studies this weekend.

Robert Kim

unread,
Sep 8, 2012, 12:16:09 AM9/8/12
to laruby...@googlegroups.com
Hi Cynthia,

First, I should mention that after creating the full_title helper from listing 5.26, Sublime Text 2 gives the following error message when I would try to save the file:

Unable to save ~/rails_projects/sample_app/spec/support/utilities.rb

I noticed this initially and forgot to mention it to you.  Now it seems apparent that this is the source of my problem.  If so, please advise.

As to your point about Michael false assumption, I interpreted your instructions to mean, find the spec/spec-helper.rb file, and replace {|f| require f} with {|f| puts "sourcing #{f}"; require f }.  I must be misinterpreting as this changed nothing.  And I don't really understand what f.to_s means.  Please clarify.  

Thank you.

PS.  Jen, feel free to chime in, as I know you have encountered this snag as well.  TY.

On Thu, Sep 6, 2012 at 10:17 PM, Cynthia Kiser <c...@ugcs.caltech.edu> wrote:

Will DelHagen

unread,
Sep 8, 2012, 12:31:35 AM9/8/12
to laruby...@googlegroups.com
Does the directory exist where you are trying to save the file?

--
Sent from 415-680-4700

Robert Kim

unread,
Sep 8, 2012, 1:17:42 AM9/8/12
to laruby...@googlegroups.com
Sorry if this isn't the information you are asking for:

If you are asking whether:

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

exists in the file that I am trying to save:

spec/support/utilities.rb

then the answer is no.  I tried pasting the Dir into utilities.rb, and this still did not allow me to save the file (i.e. I still receive the "Unable to save..." error message).

- Rob, the newb

Will DelHagen

unread,
Sep 8, 2012, 3:20:10 PM9/8/12
to laruby...@googlegroups.com
Does the directory exist on your local file system?  

Exactly how did you create the file and how are you trying to save it. This is a total shot in the dark, but I thought maybe you had not created the directory where you are trying to save the file. 

This is not a Rails or Ruby problem.  Sublime Text is just a text editor and you're just trying to save a file. If you opened that 'file' for editing through the command line, I think it's possible that you don't have the directory. 

Two options:
1) use mkdir to create the directory(ies) you need. 
2) use [Save as] in Sublime text and create the directories via the native OSX file system explorer. 

Will

--
Sent from 415-680-4700

Will DelHagen

unread,
Sep 8, 2012, 3:29:09 PM9/8/12
to laruby...@googlegroups.com
I mean this with all the solidarity and sincerity of someone who was in your shoes not too long ago Robert. It seems like you might want to go through a *Ruby* tutorial before jumping into Hartl's book. The syntax will make a lot more sense to you then. 

For example, you will recognize right away what this code is doing:
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

There is a lot going on in that one line, which is something awesome about Ruby, but which takes some getting used to. 

That said, I've been through every line of code and every optional exercise in the Rails Tutorial and if you decide to go it "the hard way" then I'm happy to keep helping. And Cynthia is obviously an awesome resource and great teacher who is really generous with her time. 

Good luck!

Will

--
Sent from 415-680-4700

Cynthia Kiser

unread,
Sep 8, 2012, 4:27:52 PM9/8/12
to laruby...@googlegroups.com
Quoting Robert Kim <robert...@gmail.com>:
> Hi Cynthia,
>
> First, I should mention that after creating the full_title helper from
> listing 5.26, Sublime Text 2 gives the following error message when I would
> try to save the file:
>
> Unable to save ~/rails_projects/sample_app/spec/support/utilities.rb
>
> I noticed this initially and forgot to mention it to you. Now it seems
> apparent that this is the source of my problem. If so, please advise.

I think it is very likely this is the source of your errors.

When you see error messages like "NoMethodError: undefined method
`full_title' for...." that means one of two things, the method does
not exist or it isn't available because the file defining it isn't
getting loaded. For me the most common problem is the method doesn't
exist - because I made a typo and called 'full_titel' instead of
'full_title' or something similar. But that did not seem to be the
case, so I guessed it was due to the 'not available' kind of error.

With your 'unable to save' message, I think we are back to debugging
the 'really does not exist' kind of error. I think Will's guess is
probably a good one - the reason SublimeText2 isn't saving your file
is because you do not have a 'support' directory inside your 'spec'
directory. In your terminal, do the following:

cd ~/rails_projects/sample_app/spec
ls -l

Do you see a directory named 'support'? and do you have permission to
write files to that directory? If the directory does not exist, create
it with:

mkdir support

Then you should be able to save utilities.rb in that directory and run
your tests.

If the directory exists, then it sounds like a permissions issue.

> As to your point about Michael false assumption, I interpreted your
> instructions to mean, find the spec/spec-helper.rb file, and replace {|f|
> require f} with {|f| puts "sourcing #{f}"; require f }. I must be
> misinterpreting as this changed nothing.

Once the file spec/support/utilities.rb exists, you should see output
on your terminal that looks something like this when you start running
tests:

sourcing utilities.rb

But I would say take that edit back out and just focus on creating
utilities.rb. That should fix the NoMethodError problems you are seeing.

Robert Kim

unread,
Sep 9, 2012, 6:33:17 PM9/9/12
to laruby...@googlegroups.com
Thanks Cynthia and Will.

I needed to create the file outside of Sublime and Terminal, which I'd grown accustomed to.  As I move along the tutorial, I'm realizing how ridiculous my questions have been thus far.  :\

Right now, I'm in Chapter 8 (or at least I was).  I was dealing with a single error having to do with the "remember token" line within user_spec.  In my attempt to solve the error by backtracking, I went from one to 18 failures.  The local host doesn't respond.  I'm lost.  If possible, please help.  I'm hoping there is an underlying problem for most of these:

Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/
FF...F..................FFFFFFFFFFFFFFF

Failures:

  1) Authentication signin page 
     Failure/Error: before { visit signin_path }
     AbstractController::ActionNotFound:
       The action 'new' could not be found for SessionsController
     # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

  2) Authentication signin page 
     Failure/Error: before { visit signin_path }
     AbstractController::ActionNotFound:
       The action 'new' could not be found for SessionsController
     # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

  3) User 
     Failure/Error: it { should respond_to(:remember_token) }
       expected #<User id: nil, name: "Example User", email: "us...@example.com", created_at: nil, updated_at: nil, password_digest: "$2a$04$lCPc0stCiyx4XAqT535q3.7TEnl3R0V1V8EPbUYxkCcC..."> to respond to :remember_token
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

  4) Static pages Help page 
     Failure/Error: before { visit help_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39ec40458>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:17:in `block (3 levels) in <top (required)>'

  5) Static pages Help page 
     Failure/Error: before { visit help_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39fafad68>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:17:in `block (3 levels) in <top (required)>'

  6) Static pages Home page 
     Failure/Error: before { visit root_path }
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007fe39e8bddf8>
     # ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  7) Static pages Home page 
     Failure/Error: before { visit root_path }
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007fe39c798b78>
     # ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  8) Static pages Home page 
     Failure/Error: before { visit root_path }
     NameError:
       undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007fe39ec864a8>
     # ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  9) Static pages About page 
     Failure/Error: before { visit about_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39e8b4fa0>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'

  10) Static pages About page 
     Failure/Error: before { visit about_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39f1f1410>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'

  11) Static pages Contact page 
     Failure/Error: before { visit contact_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39f75fbb8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:31:in `block (3 levels) in <top (required)>'

  12) Static pages Contact page 
     Failure/Error: before { visit contact_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39ec43f40>:0x007fe39fb3ea90>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/static_pages_spec.rb:31:in `block (3 levels) in <top (required)>'

  13) User pages signup page 
     Failure/Error: before { visit signup_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39e82b4d0>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:16:in `block (3 levels) in <top (required)>'

  14) User pages signup page 
     Failure/Error: before { visit signup_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39c4995a8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:16:in `block (3 levels) in <top (required)>'

  15) User pages profile page 
     Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39f0b35f8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  16) User pages profile page 
     Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39ec6bcc0>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  17) User pages signup with invalid information should not create a user
     Failure/Error: before { visit signup_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39ec962e0>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:24:in `block (3 levels) in <top (required)>'

  18) User pages signup with valid information should create a user
     Failure/Error: before { visit signup_path }
     ActionView::Template::Error:
       undefined local variable or method `root_path' for #<#<Class:0x007fe39e827970>:0x007fe39c4a1de8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___1072174696357414959_70307801136900'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1319578714786927615_70307799698760'
     # ./spec/requests/user_pages_spec.rb:24:in `block (3 levels) in <top (required)>'

Finished in 1.39 seconds
39 examples, 18 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:10 # Authentication signin page 
rspec ./spec/requests/authentication_pages_spec.rb:11 # Authentication signin page 
rspec ./spec/models/user_spec.rb:17 # User 
rspec ./spec/requests/static_pages_spec.rb:19 # Static pages Help page 
rspec ./spec/requests/static_pages_spec.rb:20 # Static pages Help page 
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page 
rspec ./spec/requests/static_pages_spec.rb:11 # Static pages Home page 
rspec ./spec/requests/static_pages_spec.rb:13 # Static pages Home page 
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages About page 
rspec ./spec/requests/static_pages_spec.rb:27 # Static pages About page 
rspec ./spec/requests/static_pages_spec.rb:33 # Static pages Contact page 
rspec ./spec/requests/static_pages_spec.rb:34 # Static pages Contact page 
rspec ./spec/requests/user_pages_spec.rb:18 # User pages signup page 
rspec ./spec/requests/user_pages_spec.rb:19 # User pages signup page 
rspec ./spec/requests/user_pages_spec.rb:11 # User pages profile page 
rspec ./spec/requests/user_pages_spec.rb:12 # User pages profile page 
rspec ./spec/requests/user_pages_spec.rb:29 # User pages signup with invalid information should not create a user
rspec ./spec/requests/user_pages_spec.rb:43 # User pages signup with valid information should create a user

Thanks!

Robert Kim

unread,
Sep 9, 2012, 6:59:04 PM9/9/12
to laruby...@googlegroups.com
Nm my last issue (phew!), although I still can not load the local host site, and I'm back to that pesky error about the remember token:

Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/models/user_spec.rb
....F.................

Failures:

  1) User 
     Failure/Error: it { should respond_to(:remember_token) }
       expected #<User id: nil, name: "Example User", email: "us...@example.com", created_at: nil, updated_at: nil, password_digest: "$2a$04$z8W6KN5VJXguxWUq4mUF.u1RSoHxuqBDVIIVKBsmS8hC..."> to respond to :remember_token
     # ./spec/models/user_spec.rb:17:in `block (2 levels) in <top (required)>'

Finished in 0.66402 seconds
22 examples, 1 failure

Failed examples:

rspec ./spec/models/user_spec.rb:17 # User 

HERE is the user_spec.rb:

require 'spec_helper'

describe User do

  before do
    @user = User.new(name: "Example User", email: "us...@example.com", 
                     password: "foobar", password_confirmation: "foobar")
  end

  subject { @user }

  it { should respond_to(:name) }
  it { should respond_to(:email) }
  it { should respond_to(:password_digest) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }
  it { should respond_to(:remember_token) }
  it { should respond_to(:authenticate) }  

  it { should be_valid }

  describe "when name is not present" do
    before { @user.name = " " }
    it { should_not be_valid }
  end

  describe "when email is not present" do
    before { @user.email = " " }
    it { should_not be_valid }
  end

  describe "when name is too long" do
    before { @user.name = "a" * 51 }
    it { should_not be_valid }
  end

  describe "when email format is invalid" do
    it "should be invalid" do
      addresses = %w[user@foo,com user_at_foo.org example.user@foo.
                     foo@bar_baz.com foo@bar+baz.com]
      addresses.each do |invalid_address|
        @user.email = invalid_address
        @user.should_not be_valid
      end      
    end
  end

  describe "when email format is valid" do
    it "should be valid" do
      addresses = %w[us...@foo.COM A_U...@f.b.org frst...@foo.jp a...@baz.cn]
      addresses.each do |valid_address|
        @user.email = valid_address
        @user.should be_valid
      end      
    end
  end

  describe "when email address is already taken" do
    before do
      user_with_same_email = @user.dup
      user_with_same_email.save
    end

    it { should_not be_valid }
  end

  describe "when email address is already taken" do
    before do
      user_with_same_email = @user.dup
      user_with_same_email.email = @user.email.upcase
      user_with_same_email.save
    end

    it { should_not be_valid }
  end

  describe "when password is not present" do
    before { @user.password = @user.password_confirmation = " " }
    it { should_not be_valid }
  end

  describe "when password doesn't match confirmation" do
    before { @user.password_confirmation = "mismatch" }
    it { should_not be_valid }
  end

  describe "when password confirmation is nil" do
    before { @user.password_confirmation = nil }
    it { should_not be_valid }
  end

  describe "with a password that's too short" do
    before { @user.password = @user.password_confirmation = "a" * 5 }
    it { should be_invalid }
  end

  describe "return value of authenticate method" do
    before { @user.save }
    let(:found_user) { User.find_by_email(@user.email) }

    describe "with valid password" do
      it { should == found_user.authenticate(@user.password) }
    end

    describe "with invalid password" do
      let(:user_for_invalid_password) { found_user.authenticate("invalid") }

      it { should_not == user_for_invalid_password }
      specify { user_for_invalid_password.should be_false }
    end
  end
end

Thanks!

Robert Kim

unread,
Sep 9, 2012, 8:07:14 PM9/9/12
to laruby...@googlegroups.com
Is there an easy answer to "how do I reconnect with the server?"  thx!

Will DelHagen

unread,
Sep 9, 2012, 8:09:10 PM9/9/12
to laruby...@googlegroups.com
Can you clarify your question?

--
Sent from 415-680-4700

Cynthia Kiser

unread,
Sep 9, 2012, 8:10:51 PM9/9/12
to laruby...@googlegroups.com
Glad you figured out your routing error; from the variety of things
that were not there, it sounded like you got rid of your entire
routes.rb file.

The remember_token error feels like you didn't run your migrations -
or even more likely ran them in dev but did not run them again in test
and didn't run 'rake db:test:prepare' which would have done that for you.

Will DelHagen

unread,
Sep 9, 2012, 8:10:55 PM9/9/12
to laruby...@googlegroups.com
Send your user.rb. 

--
Sent from 415-680-4700

Robert Kim

unread,
Sep 9, 2012, 8:18:00 PM9/9/12
to laruby...@googlegroups.com
Hi Will, 

Well, I was on Chapter 8 of the tutorial.  I've been pushing to GitHub and Heroku at the end of every previous chapter.

Somehow, my sample app is no longer connected to the rails server where i can normally access my work at http://localhost:3000.

I've basically gone back to square one, redoing my work for the app, but this is turning out to be ineffective.  

Short of starting the entire sample app from the beginning (and deleting the one I've been working on, I don't have a clue.

BTW, if I sound panicky, it's because i'm on a time constraint.  thanks to everyone for your patience with my inquiries. 

Cynthia Kiser

unread,
Sep 9, 2012, 8:21:18 PM9/9/12
to laruby...@googlegroups.com
Quoting Robert Kim <robert...@gmail.com>:
> Somehow, my sample app is no longer connected to the rails server where i
> can normally access my work at http://localhost:3000.

Is the server running? Go to the terminal where you started the rails
server, stop it if it is running, and start it again. Report success
or any error messages you receive.

Robert Kim

unread,
Sep 9, 2012, 8:27:09 PM9/9/12
to laruby...@googlegroups.com
Hi Cynthia,

Could this have happened from my using Ctrl-D and Ctrl-C while in rails console?  

Anyways, to your question, I don't know how to "go to the terminal", but...

This is what I get from Terminal:

Roberts-MacBook-Air:sample_app robertjoonkim$ rails server
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-09-09 17:20:28] INFO  WEBrick 1.3.1
[2012-09-09 17:20:28] INFO  ruby 1.9.3 (2012-04-20) [x86_64-darwin11.4.0]
[2012-09-09 17:20:28] WARN  TCPServer Error: Address already in use - bind(2)
Exiting

Cynthia Kiser

unread,
Sep 9, 2012, 8:44:04 PM9/9/12
to laruby...@googlegroups.com
That is the terminal.

So you need to find and kill the hung process that is bound to port 3000

$ ps axw | grep ruby
24318 s006 S+ 0:00.00 grep ruby
24293 s007 S+ 0:03.05 ruby script/server

The first number is the process ID (aka pid). You want to kill the
process that looks like your server. For me what is the second
line. Yours will look slightly different because you are running Rails
3 and webrick.

$ kill 24293

Robert Kim

unread,
Sep 9, 2012, 8:53:19 PM9/9/12
to laruby...@googlegroups.com
I found this on google:

subl /etc/hosts

which gave me this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

Please please please advise. :\

Cynthia Kiser

unread,
Sep 9, 2012, 9:04:49 PM9/9/12
to laruby...@googlegroups.com
That is completely unrelated to running your rails server.

Cynthia Kiser

unread,
Sep 9, 2012, 9:14:58 PM9/9/12
to laruby...@googlegroups.com
Other options that will work:

reboot your mac - that will kill the server running on port 3000

run your server on a different port for now:

$ rails server -p 3001

Robert Kim

unread,
Sep 9, 2012, 9:31:03 PM9/9/12
to laruby...@googlegroups.com
Thanks.  I figured out what you were saying in your initial method and managed to kill, and get back to the server, yet only to my sample app's tangential pages (help, sign in), not the home page.   

in any case, i'll keep reworking to see if I can fix this. much thanks.

Brad Graham

unread,
Sep 10, 2012, 2:15:23 PM9/10/12
to laruby...@googlegroups.com
Hey Robert,

I might also suggest checking out OC-LA Ruby on Rails meetup. The group is focused a bit more towards Ruby/Rails beginners and they just started going through the Hartl book last week.

Rob Kim

unread,
Sep 10, 2012, 4:27:16 PM9/10/12
to laruby...@googlegroups.com, laruby...@googlegroups.com
Great thanks, Brad.  Ill try to check it out.

- Robert Kim

Robert Kim

unread,
Sep 11, 2012, 3:17:20 PM9/11/12
to laruby...@googlegroups.com
Hello everyone,

Got stuck again, this time deep into Chapter 9.  Tried to start the chapter over by copying code that I pushed in Chap 8 to GitHub, thinking I could get a fresh start.  Not happening.  The very first test of Chap 9,  I run into the following:

Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/user_pages_spec.rb -e "edit page"
Run options: include {:full_description=>/edit\ page/}
FFF

Failures:

  1) User pages edit page 
     Failure/Error: it { should have_selector('h1',    text: "Update your profile") }
       expected css "h1" with text "Update your profile" to return something
     # ./spec/requests/user_pages_spec.rb:64:in `block (4 levels) in <top (required)>'

  2) User pages edit page 
     Failure/Error: it { should have_link('change', href: 'http://gravatar.com/emails') }
       expected link "change" to return something
     # ./spec/requests/user_pages_spec.rb:66:in `block (4 levels) in <top (required)>'

  3) User pages edit page 
     Failure/Error: it { should have_selector('title', text: "Edit user") }
       expected css "title" with text "Edit user" to return something
     # ./spec/requests/user_pages_spec.rb:65:in `block (4 levels) in <top (required)>'

Finished in 0.69431 seconds
3 examples, 3 failures

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:64 # User pages edit page 
rspec ./spec/requests/user_pages_spec.rb:66 # User pages edit page 
rspec ./spec/requests/user_pages_spec.rb:65 # User pages edit page 


Is there something lingering from my initial work in Chapter 9 that I'm unable to wipeout with Chap 8's code?

Thanks for your help.

Han Kang

unread,
Sep 11, 2012, 9:24:16 PM9/11/12
to laruby...@googlegroups.com
can you link your github account? i can't really tell anything from only what you've written here..
--
Han Kang

Cynthia Kiser

unread,
Sep 14, 2012, 11:25:52 AM9/14/12
to laruby...@googlegroups.com
Quoting Robert Kim <robert...@gmail.com>:
> Got stuck again, this time deep into Chapter 9. Tried to start the chapter
> over by copying code that I pushed in Chap 8 to GitHub, thinking I could
> get a fresh start. Not happening.

Robert, did you get unstuck? If not, please do post a link to where we
can get your code to have a look. The previous issues you were having
were isolated enough that we could guess from the stack traces but
nothing is jumping out at me from these error messages. Often when I
get a bunch of errors it is because there is something more
fundamentally wrong. Because all 3 of these view tests error, I would
start by seeing if the view is getting rendered in your test and
having it print the rendered text so that I could look for the items
you are testing for.

Rob Kim

unread,
Sep 14, 2012, 11:39:57 AM9/14/12
to laruby...@googlegroups.com, laruby...@googlegroups.com
Cynthia,

I forgot to update you that I finished the tutorial already. Thanks for your help along the way.

- Robert Kim

Kris Mulyandani Putra

unread,
Sep 25, 2013, 12:57:16 AM9/25/13
to laruby...@googlegroups.com
Try this and it should work

require 'spec_helper'

describe "Static pages" do

  subject { page }

  describe "Home page" do
    before { visit root_path }

    it { should have_selector('h1',    text: 'Sample App') }
    it { should have_selector('title', content: full_title('')) }
    it { should_not have_selector 'title', text: '| Home' }
  end

  describe "Help page" do
    before { visit help_path }

    it { should have_selector('h1',    text: 'Help') }
    it { should have_selector('title', content: full_title('Help')) }
  end

I changed the text: symbol to content: and it works for me, im using capybara 1.1.2

On Thursday, September 6, 2012 9:28:36 PM UTC+7, Robert Kim wrote:
First off, it was great attending my first meetup with you all.  Definitely opened my eyes to what RoR can do.

On to my issue, as you may remember, I'm trying to work my way through the Hartl tutorial (for better or worse), and I ran across an error message having to do with syntax.  From what I can surmise, it is coming from below (Section 4.1, Listing 4.4 - "Updated tests for the Home page’s title. spec/requests/static_pages_spec.rb"):

require 'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the h1 'Sample App'" do
      visit '/static_pages/home'
      page.should have_selector('h1', :text => 'Sample App')
    end

    it "should have the base title" do
      visit '/static_pages/home'
      page.should have_selector('title',
                        :text => "Ruby on Rails Tutorial Sample App")
    end

    it "should not have a custom page title" do
      visit '/static_pages/home'
      page.should_not have_selector('title', :text => '| Home')
    end
  end
  .
  .
  .
end

The actual error reads:
Roberts-MacBook-Air:sample_app robertjoonkim$ bundle exec rspec spec/requests/static_pages_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load': /Users/robertjoonkim/rails_projects/sample_app/spec/requests/static_pages_spec.rb:24: syntax error, unexpected '.' (SyntaxError)
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
	from /usr/local/rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

Hopefully, someone here can spot the error, or point me in the right direction if it's some other issue.

Thanks!
Reply all
Reply to author
Forward
0 new messages