RSpec supports the concept of an "implicit" subject. If your first argument to the describe block is a class, RSpec automatically makes an instance of that class available to your specifications. See http://relishapp.com/rspec/rspec-core/v/2-6/dir/subject/implicit-subject .
require 'spec_helper' describe User do it "must have a first name" do subject.should have(1).error_on(:first_name) end it "must have a last name" do subject.should have(1).error_on(:last_name) end end
which leads to the conclusion of RSpec (if - format documentation is used):
User must have a first name must have a last name
You can reduce it even further if you are happy with the default RSpec output options:
require 'spec_helper' describe User do it { should have(1).error_on(:first_name) } it { should have(1).error_on(:last_name) } end
that leads to:
User should have 1 error on :first_name should have 1 error on :last_name
source share