Skip to content

Instantly share code, notes, and snippets.

@elle
Forked from anonymous/gist:4705398
Last active December 12, 2015 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elle/4710618 to your computer and use it in GitHub Desktop.
Save elle/4710618 to your computer and use it in GitHub Desktop.
# Minitest examples
# wishful
describe Person do
describe 'indirect' do
subject { Person.new({pet: true}) }
it { must_be :pet? }
end
end
# current
# Example 1: using valid_attributes [3]
describe Person do
context 'should have validations' do
subject { Person.new }
it { must have_valid(:name).when(sentence) }
it { wont have_valid(:name).when(nil, '') }
end
end
# Example 2
describe Person do
let(:person) { Person.new({pet: true}) }
it 'has a pet' do
assert person.pet?
end
end
# Example 3
describe Person do
subject { Person.new("Yukihiro", "Matsumoto") }
it "has a full name" do
subject.full_name.must_equal "Yukihiro Matsumoto"
end
end
And
# Example 4
describe Person do
subject { Person.new }
specify { subject.posts.must_be_empty }
end
Links:
[1] http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9
[2] https://github.com/zenspider/minitest-matchers
[3] https://github.com/wojtekmach/valid_attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment