Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Jacob Smith
Jacob Smith
10,926 Points

First Rspec Test: unexpected end-of-input, expecting keyword_end

Up to this point I don't know where I went wrong. This is the second watching these videos and I am still having issues.

What am I doing wrong?

Seth Kroger
Seth Kroger
56,413 Points

From the error message accidentally left off an 'end' statement to one of your blocks so they aren't nested properly. Go ahead and post the code file causing that error so we can help find it.

Jacob Smith
Jacob Smith
10,926 Points

I am currently using Sublime Text 2. What would be the best way to share the code file?

Seth Kroger
Seth Kroger
56,413 Points

Copy and paste it inside a of a block with 3 backticks as shown in the markdown cheatsheet.

 ```ruby

[code goes here]

 ```

Jacob Smith
Jacob Smith
10,926 Points

I ran this on the command line:

bin/rspec spec/features/todo_lists/create_spec.rb

/home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load': /home/treehouse/projects/odot/spec/features/todo_lists/create_spec.rb:8: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
 end   

    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
    from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'
Jacob Smith
Jacob Smith
10,926 Points

Okay. I was able to find out my syntax error. You were right I was missing an 'end' in my ruby code. But now, due to the updated versions of rspec (I think) I received this message.

Deprecation Warnings:

--------------------------------------------------------------------------------
RSpec::Core::ExampleGroup#example is deprecated and will be removed
in RSpec 3. There are a few options for what you can use instead:

  - rspec-core's DSL methods (`it`, `before`, `after`, `let`, `subject`, etc)
    now yield the example as a block argument, and that is the recommended
    way to access the current example from those contexts.
  - The current example is now exposed via `RSpec.current_example`,
    which is accessible from any context.
  - If you can't update the code at this call site (e.g. because it is in
    an extension gem), you can use this snippet to continue making this
    method available in RSpec 2.99 and RSpec 3:

      RSpec.configure do |c|
        c.expose_current_running_example_as :example
      end

(Called from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/capybara-2.1.0/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>')
--------------------------------------------------------------------------------

I understand that I can run the suggested code, but not really understanding what is happening? Can you help explain?

Seth Kroger
Seth Kroger
56,413 Points

I meant the .rb file that is causing the error, not the error output.

(The error means there is a syntax error in the code you wrote. Every 'do' block (or 'def', 'class', or 'module') needs a corresponding 'end' at the signify the end of the code block.)

Jacob Smith
Jacob Smith
10,926 Points

This first code is in my spec/features/todo_lists/create_spec.rb

require 'spec_helper'

describe "Creating todo lists" do 

  it "redirects to the todo list index page on success" do
    visit "/todo_lists" 
    click_link "New Todo list"
    expect(page).to have_content("New Todo List")

    fill_in "Title", with: "My todo list"
    fill_in "Description", with: "This is what I'm doing today." 
    click_button "Create Todo list"

    expect(page).to have_content("My todo list")   
   end       

    it "displays an error when the todo list has no title" do 
      expect(TodoList.count).to eq(0)

      visit "/todo_lists" 
      click_link "New Todo list"
      expect(page).to have_content("New Todo List")

      fill_in "Title", with: ""
      fill_in "Description", with: "This is what I'm doing today." 
      click_button "Create Todo list"

      expect(page).to have_content("error") 
      expect(TodoList.count).to eq(0)

      visit "/todo_lists"
      expecte(page).to_not have_content("This is what I'm doing today.")
    end 

    it "displays an error when the todo list has a title less than 3 characters" do 
      expect(TodoList.count).to eq(0)

      visit "/todo_lists" 
      click_link "New Todo list"
      expect(page).to have_content("New Todo List")

      fill_in "Title", with: "hi"
      fill_in "Description", with: "This is what I'm doing today." 
      click_button "Create Todo list"

      expect(page).to have_content("error") 
      expect(TodoList.count).to eq(0)

      visit "/todo_lists"
      expecte(page).to_not have_content("This is what I'm doing today.")
    end         
end   

In my app/concerns/todo_list.rb file

class TodoList < ActiveRecord::Base
    validates :title, presence: true
    validates :title, length: { minimum: 3 }
end

As of now I should have no errors, since I have been following the videos closely, but it says I have two failures on lines 17 and 36.