← Back to Upcase

Writing specs for the shouter app

(Charlieanna) #1

@halogenandtoast I started the workshop by writing specs for the app. i was able to write tests for the first video where everything was working because I did not wanted to test the app manually. But then when you started to change things by introducing the dashboard variable and also by starting to use polymorphism I could not understand how to write specs then.

Do you right specs from integration first and then controller specs and then model specs and then you try to make the new change work?

But what should I have done when you introduced the text shout variable and the photoshout variable?

This is the file I got to pass until I stopped testing.

require 'spec_helper' 

describe "After user signs in" do
	before do
	  visit new_user_path
          fill_in "Username",with: "Ankur Kothari"
	  fill_in "Email",with: "admin@admin.com"
	  fill_in "Password",with: "akk322"
          click_button "Sign up"
	it "can create a new shout" do
	  fill_in "Body",with: "How are you?"
          click_button "Text Shout!"
          page.should have_link "Ankur Kothari"
          page.should have_content "shouted"
          page.should have_content "How are you?"
  it "click on a user" do
	  fill_in "Body",with: "How are you?"
          click_button "Text Shout!"
          within("#shout_user") do
            click_link "Ankur Kothari"

  it "create a new photo shout" do
    page.attach_file("Image", '/Users/apple/Desktop/ios.png')
    click_button "Photo Shout!"

require 'spec_helper'

describe Shout do
	it {should respond_to(:content_id)}
	it {should respond_to(:content_type)}
	it {should belong_to(:user)}

(Matthew Mongeau) #2

@charlieanna on a day to day basis we do integration testing first. We typically don’t write controller specs because our integration tests provide us with the coverage we’re looking to test. So for instance without a controller spec, changing over to the dashboard variable would have broken 0 tests which is what we want in a refactoring. When I introduce the polymorphism I would have just created two integration tests, one for PhotoShouts and one for TextShouts, hopefully this answers your question!

(Charlieanna) #3

So integration tests and model specs. I was watching the other workshop on testing. Even there there are no controller specs, integration and model only. I will try to start the shouter app again with testing and merging both the controllers.


(Charlieanna) #4

By the way thanks for the wonderful explanation on the following users concept. The has_many :followed_users :followers, :class_name and :through, all make sense to me now. I even had an
interviewer ask me how would I implement following users concept using AR.

I might get selected.


(Charlieanna) #5

But you will write model specs for the dashboard and the timeline right ? And the search functionality using integration and then model specs?

(Charlie Gaines) #6

@halogenandtoast, any thoughts on this?


(Charlieanna) #7

I think Matt did not mean that writing controller specs are a bad thing but in this case of the shouter app writing a controller spec would not served any purpose.