it "downcases the location on save" do
expect(user.location).to eq "default"
end
Note: The first thing you may find asking yourself is "Where does the user variable come from?"
before do
user = create(:user, location: 'default')
end
it "downcases the location on save" do
user = create(:user)
expect(user.location).to eq "default"
end
Note: The first thing you may find asking yourself is "Why is the location set to 'default'"
FactoryBot.define do
factory :user do
location 'default'
end
end
let!(:person) {
create :person,
gender: female,
date_of_birth: date_of_birth,
city_of_birth: city,
state_of_birth: state,
country_of_birth: country,
county_of_birth: county,
number_of_dependents: dependents,
nickname: nickname,
materials_under_another_name: materials,
alt_first_name: alt_first,
alt_middle_name: alt_middle,
alt_last_name: alt_last,
}
let(:person_presenter) {
PersonPresenter.new(person)
}
describe '#person_presenter' do
specify { person_presenter('birth_location').must_include city.name }
end
Note: In this example, each of the variables inside the let is another let that makes one or more calls to the database. Notice that this is a let!, so it will execute before each spec, adding 7 seconds for each test even if the other tests don't reference the data.
describe '#person_presenter' do
it "shows the birth location as the city" do
city_name = "Raleigh"
city = build_stubbed(:city, name: city_name)
person = build_stubbed(:person, city_of_birth: city)
presenter = PersonPresenter.new(person)
presenter("birth_location").must_include city_name
end
end
- Write more unit specs?
- Write more request specs?
- Try it out in our main app?