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('us@gmail.com').for(:email) } it { should allow_value('us.vn@gmail.com').for(:email) } it { should allow_value('us_vn@gmail.com').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¶ ↑
-
Fork it
-
Create your feature branch (‘git checkout -b my-new-feature`)
-
Commit your changes (‘git commit -am ’Added some feature’‘)
-
Push to the branch (‘git push origin my-new-feature`)
-
Create new Pull Request
Copyright¶ ↑
Copyright © 2013 nqtien310@gmail.com.