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 Creating Methods in Tests

Purvi Agrawal
Purvi Agrawal
7,960 Points

Unable to create methods in test

I am trying to create a method in test for Ruby on Rails Todo list Application. I am doing exactly same as what done in the video but I getting the below error

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in load': C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:5: syntax error, unexpected tSTRING_BEG (SyntaxError) def "Create_todo"(options{}) ^ C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:5: syntax error, unexpected '(', expecting keyword_end def "Create_todo"(options{}) ^ C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:5: syntax error, unexpected ')', expecting keyword_end def "Create_todo"(options{}) ^ C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:6: syntax error, unexpected tOP_ASGN, expecting keyword_end options [:title] ||="Purvi" ^ C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:7: syntax error, unexpected tOP_ASGN, expecting keyword_end options [:details] ||="Meh" ^ C:/Users/user/Documents/odot/spec/features/todo/create_todo.rb:90: syntax error, unexpected keyword_end, expecting end-of-input from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inblock in load_spec_files' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in each' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inload_spec_files' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in run' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:inrun' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'

Here is my code

require 'spec_helper'

describe "Creating Todo List" do

    def "Create_todo"(options{})
        options [:title] ||="Purvi"
        options [:details] ||="Meh"      

        visit "/todos"
        click_link "New Todo"
        expect(page).to have_content("New Todo")

        fill_in "Title", with: options[:title]
        fill_in "Details", with: options[:details]
        click_button "Create Todo"      
    end

    it "Redirects to the todos index page on success" do
        Create_todo
        expect(page).to have_content("Purvi")
    end

    it "Fails if there is no todos title" do
        expect(Todo.count).to eq(0) 
        visit "/todos"
        click_link "New Todo"
        expect(page).to have_content("New Todo")

        fill_in "Title", with: ""
        fill_in "Details", with: "Meh"
        click_button "Create Todo"

        expect(page).to have_content("error")
        expect(Todo.count).to eq(0) 
        visit "/todos"
        expect(page).to_not have_content("Meh")

    end

    it "Fails if the todos title is less than 3 characters" do
        expect(Todo.count).to eq(0) 
        visit "/todos"
        click_link "New Todo"
        expect(page).to have_content("New Todo")

        fill_in "Title", with: "hi"
        fill_in "Details", with: "Meh"
        click_button "Create Todo"

        expect(page).to have_content("error")
        expect(Todo.count).to eq(0) 
        visit "/todos"
        expect(page).to_not have_content("Meh")

    end

    it "Fails if the todos has no details" do
        expect(Todo.count).to eq(0) 
        visit "/todos"
        click_link "New Todo"
        expect(page).to have_content("New Todo")

        fill_in "Title", with: "Grocery"
        fill_in "Details", with: ""
        click_button "Create Todo"

        expect(page).to have_content("error")
        expect(Todo.count).to eq(0) 
        visit "/todos"
        expect(page).to_not have_content("Grocery")

    end

    it "Fails if the todos details is less than 3 characters" do
        expect(Todo.count).to eq(0) 
        visit "/todos"
        click_link "New Todo"
        expect(page).to have_content("New Todo")

        fill_in "Title", with: "getta"
        fill_in "Details", with: "M"
        click_button "Create Todo"

        expect(page).to have_content("error")
        expect(Todo.count).to eq(0) 
        visit "/todos"
        expect(page).to_not have_content("getta")

    end
end
Purvi Agrawal
Purvi Agrawal
7,960 Points

Jason Seifer Can you please help. Is it because of the rspec version ? I have been stuck on this for quite a while now.

1 Answer

You can't do

def "Create_todo"(options{})

You can't type the method name as a string. It should probably be:

def create_todo(options{})

and then change references to that method in your tests accordingly. But I'm not sure if you can do (options{}) and I can't be bothered to check right now. Maybe you can check that yourself or someone else will chime in.