← Back to Upcase

Creating the First Todo

(Greg Zentkovich) #4

Wow! the was so simple to fix… and so easily missed… I guess it takes a experienced and trained eye… Buy milk and Buy Milk. Case-sensitive…hmm. Thanks for going the extra mile (i.e. deciphering my spaghetti code)… I had to have that green! :grinning:

(Thomas Nys) #5

I installed the last versions of both capybara and RSpec and I’m not getting the same warnings when interacting trough the feauture. For example when altering the view I should get a warning of a non existing path. I seems like I am only getting warnings about a view elements.

(Thomas Nys) #6

Nevermind I restarted config from scratch and everything was working as expected. :slight_smile:

(Ben Akroyd) #7

When I run

rspec spec/features/user_creates_todo_spec.rb

I get

/usr/lib/ruby/vendor_ruby/bundler/runtime.rb:34:in `block in setup’: You have already activated rspec-support 3.4.1, but your Gemfile requires rspec-support 3.0.4. Prepending “bundle exec” to your command may solve this. (Gem::LoadError)

Indeed, when I prepend the command with “bundle exec” it works. However, when I went to correct the gemfile, there wasn’t an obvious place to correct. Any insight as to what I should change so that my initial command will execute cleanly?

(Ben Linville) #8

My test passes when it shouldn’t. (I fill_in “Buy milk” and expect “Buy bread”) Anybody care to help me understand why rspec isn’t checking the li’s text to make sure its a match?
Here’s my code: https://github.com/bjlinville1/upcase_tdd_trail/blob/working-branch/spec/features/user_creates_todo_spec.rb

(Joseph Crocetta) #10

I hit the wrong reply button.
Are you clearing out your database after every test?

(Joseph Crocetta) #11

Check this out

(Ben Linville) #12

That would make sense. I originally had them matching, so the db would have a few objects that pass. Thanks!

(Daniel Uribe) #13

Great explanation. I had a similar issue to and cleared it up with after thinking the problem was something else.

(Denis Hovart) #14

Thanks for this serie.
I am nitpicking a bit, but the HTTP spec requires a fully qualified URL when doing 302 redirects. For this reason DHH recommends using model_url instead of model_path with redirect_to in Agile Web Development with Rails.

(Wade Carlson) #15

Not sure why I am getting this error when I run bundle exec rspec I’ve tried to google it but can’t seem to find the solution. Any guidance would be great! Just signed up today, thanks!

Failure/Error: click_on “Add a new todo”

   Unable to find link or button "Add a new todo"

Test Code - /spec/features/user_creates_todo_spec.rb

require "rails_helper"

feature "User creates todo" do
  scenario "succesfully" do
    click_on "Add a new todo"
    fill_in "Title", with: "Buy milk"
    click_on "Submit"

expect(page).to have_css ".todos li", text: "Buy milk"

Index - app/views/index.html.erb

<%= link_to "Add a new todo", new_todo_path %>

Routes are good to go - config/routes.rb

Rails.application.routes.draw do
root to: "todos#index"
resources :todos, only: [:new, :create]


Controller looks good to go -

class TodosController < ApplicationController
def index

def new
  @todo = Todo.new

Gem file -

group :development, :test do
gem 'rspec-rails', '~> 3.5'
gem 'byebug', platform: :mri

group :test do
gem 'capybara', '~> 2.3.0'

(Joseph Crocetta) #16

Just skimmed over your issue but looks like you never visited the page in your test.

(mciul) #17

My new template is not rendering for some reason. I got an error that it was ‘Unable to find field “Title”’, so I ran the rails server and looked at the new page myself. Sure enough, it has the Application layout header but nothing from the new template.


<!DOCTYPE html>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

  <%= yield %>



<% form_for @todo do |form| %>
  <%= form.label :title %>
  <%= form.text_field :title %>
<% end %>

What am I doing wrong?

(mciul) #18

I think I figured it out. It was the wrong choice of erb tags in the new page - the “form_for” line needs an =, while the “end” tag will throw an error if it has an =. I don’t really understand why, though.

(Danelson Rosa) #19

Hey, when you have an ERB tag with an equal sign, i.e. <%= @foo %>, it displays something to the screen. As you saw in your example, if you don’t include it within the opening form tag, then the form won’t be shown.

Check this out: https://stackoverflow.com/questions/7996695/what-is-the-difference-between-and-in-erb-in-rails.

(mciul) #20

Right, but why do I get an error when the “end” tag has an =?

(Danelson Rosa) #21

It’s a syntax error – end tags just aren’t supposed to have equal signs.

(Prasunjit) #22

Not sure if I should ask this here. Could somebody tell how to use both the vi editor and the terminal horizontally stacked upon one another like in the video, I could understand though how you are splitting the editor. It makes the dev process a lot easier

(Chris Toomey) #23

Josh is using tmux in these videos. Coincidentally we have a whole course on tmux here on Upcase if you want to learn more :slight_smile:

(Prasunjit) #24

Thanks, loved that switch mode, productive for the dev process, I thought he was using screen or some commands on the iTerm