QuickShoulda

<img src=“https://badge.fury.io/rb/quick_shoulda.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/nqtien310/quick_shoulda.png?branch=master” alt=“Build Status” />

A Rails generator which automatically generates Shoulda test cases ,

Just by specifying path to your model file , a bunch of Shoulda test cases will be generated for you in the correspondent spec file

Examples :

Sample model :

app/models/user.rb

class User < ActiveRecord::Base
  validates :username , :presence => true
  validates :email, :format => EmailRegex, :uniqueness => true

  has_many :posts
  has_many :comments, :through => :posts
end

Just 1 simple command

Rails generate quick_shoulda:g User
or
Rails generate quick_shoulda:g app/models/user.rb

These lines will be added to spec/models/user_spec.rb ( QuickShoulda will automatically create this file if it’s not yet created )

describe 'User' do
  describe '#Validations' do
    it { should validate_presence_of(:username) }
    it { should validate_uniqueness_of(:email) }
    it { should allow_value('[email protected]').for(:email) }
    it { should allow_value('[email protected]').for(:email) }
    it { should allow_value('[email protected]').for(:email) }
  end

  describe '#Associations' do
    it { should have_many(:posts) }
    it { should have_many(:comments).through(:posts) }
  end
end

Installation

gem install 'quick_shoulda'

or add to Gemfile:

group :development do
  gem 'quick_shoulda'
end

Usage

Path to model file as parameter

Rails generate quick_shoulda:g app/models/user.rb

Model name as parameter

Rails generate quick_shoulda:g User

multi model name / paths as parameter

Rails generate quick_shoulda:g User Post Comment Admin::Statistic
or
Rails generate quick_shoulda:g app/models/user.rb app/models/post.rb

Configurations

Install config file by

Rails generate quick_shoulda:install

This will place the .qshoulda.yml in the root path , then edit this file for configuration purpose

Config location to put the generated spec files

spec_folder: test/models

Contributing

  1. Fork it

  2. Create your feature branch (‘git checkout -b my-new-feature`)

  3. Commit your changes (‘git commit -am ’Added some feature’‘)

  4. Push to the branch (‘git push origin my-new-feature`)

  5. Create new Pull Request

Copyright © 2013 [email protected].