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

Code explanation

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 "Diplays 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"
    expect(page).to_not have_content("This is what I'm doing today")

  end

end

Can someone please explain to me what this code actually means? I am going through the video but do not get what is going on?

thanks in advanced!

3 Answers

Neil Northrop
Neil Northrop
5,095 Points

Mahmud,

Will you try posting all that code again but add ruby after the first set of backtick marks?

Click on the link under your text input box marked Markdown Cheatsheet. It has a section on wrapping your code with 3 backtick marks and the programming language you're using before the code and 3 backtick marks after the code. So after the first 3 backtick marks add ruby, press enter, then paste in your code.

Try that out and it'll show up better for everyone else to read.

Thanks!

Hey thanks! I learnt something new! found the backticks too!

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Mahmud Hussain! Great question. In the first test, we're making sure that we go to the right page when we successfully enter a todo list. We enter the information just like we would in a web browser and then make sure that we're correctly navigated back. In the second test we make sure that leaving out a vital attribute displays an error on the page and also that no extra todos were created in the database.