Testing with RSpec and Factory Girl

Testing has been a huge pain in the ass lately. I’ve been going through a learning curve and it sucks to know how to write the code to accomplish something, but not know how to write the freakin test. All of my tests initially relied upon seed data. Now I’m using FactoryGirl. But I’ve got all these dumb-ass associations that are complex. How the fuck do I handle them appropriately in a test? IS IT WORTH IT?!

I’m not sure it is worth it. But I feel like testing has it’s merrits. I fucking hate testing. But testing is good.

Install Rspec

$ rails g rspec:install

Update Gemfile

    gem "factory_girl", "~> 4.0"
    gem "rspec-rails"

As I write more code, I realize testing from the get-go is important.

Example rspec Test, NO FACTORY GIRL

describe "#promote_to_admin" do
  it "makes a regular membership an admin membership" do
    membership = Membership.new(admin: false)


    expect(membership.admin?).to eq(true)


Post Content