Warp provides a selection of inteligent RSpec matchers for your model, controller and feature specifications.
Warp's matchers are written to be intuitive, easy to use, and to avoid testing Rails itself. The matchers also take advantage of RSpec's composing matchers wherever possible.
Compatible with:
- Ruby 1.9.3 and greater
- Rails 3.2 and greater
- RSpec 3.0.0 and greater
Add this line to your application's Gemfile:
gem "warp"
And then execute:
$ bundle
Ensures that the specific assign is set:
specify { expect(controller).to assign(:posts) }
Ensures that the specific assign is set with the specified value:
specify { expect(controller).to assign(:posts).with(posts) }
Ensures that the specific assign is set with an instance of the specified class:
specify { expect(controller).to assign(:post).with_a(Post) }
Ensures that the specific assign is set with a instance of the specified class that is not persisted:
specify { expect(controller).to assign(:post).with_a_new(Post) }
Ensure that the specific flash key is set:
specify { expect(controller).to set_flash(:notice) }
Ensure that the specific flash key is set:
specify { expect(controller).to set_flash(:notice).to("Your order has been processed.") }
Ensures that a belong_to
association is present:
specify { expect(comment).to belong_to(:post) }
Works with either model classes or model objects.
Ensures that a has_many
association is present:
specify { expect(post).to have_many(:comments) }
Ensures that a has_one
association is present:
specify { expect(person).to have_one(:address) }
Ensures that a has_and_belongs_to_many
association is present:
specify { expect(group).to have_and_belong_to_many(:users) }
This matcher is not avaliable on Rails 4.1+, as these versions of Rails will create a has_many :though
association instead of a 'has_and_belongs_to_many' association.
Checks if a certain attribute is present on a model. Works against models or model instances.
specify { expect(user).to have_attribute(:name) }
All validation matchers can be specified with, or without options to verify.
Ensures that a validates_acceptance_of
validator is present on the attribute.
specify { expect(user).to validate_acceptance_of(:terms) }
Ensures that a validates_absence_of
validator is present on the attribute.
Only avaliable on Rails 4+.
specify { expect(user).to validate_absence_of(:postcode, if: :non_us_address) }
Ensures that a validates_confirmation_of
validator is present on the attribute.
specify { expect(user).to validate_confirmation_of(:password) }
Ensures that a validates_exclusion_of
validator is present on the attribute.
specify { expect(user).to validate_exclusion_of(:age, in: 0..17) }
Ensures that a validates_format_of
validator is present on the attribute.
specify { expect(user).to validate_format_of(:postcode, with: /\d{5,8}/) }
Ensures that a validates_inclusion_of
validator is present on the attribute.
specify { expect(user).to validate_inclusion_of(:role, in: ["develop", "design"]) }
Ensures that a validates_length_of
validator is present on the attribute.
specify { expect(user).to validate_length_of(:name, in: 5..25) }
Ensures that a validates_numericality_of
validator is present on the attribute.
specify { expect(user).to validate_numericality_of(:age) }
Ensures that a validates_presence_of
validator is present on the attribute.
specify { expect(user).to validate_presence_of(:name) }
Ensures that a validates_association_of
validator is present on the attribute.
specify { expect(user).to validate_association_of(:profile) }
Ensures that a validates_uniqueness_of
validator is present on the attribute.
specify { expect(user).to validate_uniqueness_of(:email, scope: :company) }
Ensures that a record is created.
specify { expect{post :create, params}.to create(Post) }
Ensures that a record is updated.
specify { expect{post :update, params}.to update(Post) }
Ensures that a record is destroyed.
specify { expect{delete :destroy, id: id}.to destroy(Post) }
- Fork it
- Create a branch (
git checkout -b super-foo
) - Add your feature and specs.
- Commit your changes (
git commit -am 'Extra-super foo-matic.'
) - Push to the branch (
git push origin super-foo
) - Create new Pull Request