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

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

1 Answer

It's because you have declared the method name as a string.

Use:

def create_todo(options{})

uppercase should not be used for methods, so make the 'c' lowercase and make sure you reference it correctly in the 'it' blocks i.e. create_todo, not Create_todo.