Skip to content

Instantly share code, notes, and snippets.

@satooshi
Created December 30, 2018 09:42
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 satooshi/ecfa3fd8e3c32819746432819678a0ff to your computer and use it in GitHub Desktop.
Save satooshi/ecfa3fd8e3c32819746432819678a0ff to your computer and use it in GitHub Desktop.
# spec/models/cat_spec.rb
require 'rails_helper.rb'
RSpec.describe Cat, type: :model do
# this is a test target model
let(:cat) { Cat.new(status: status) }
# this block describes Cat#nyan instance method
# when you reference an instance method, write `Class#method`
# and for a class method, write 'Class.method'
describe '#nyan' do
# this is the test target
# and can be referenced as `subject`
subject { cat.nyan }
# and this block describes test conditions
context 'When a cat is hungry' do
# this is the first test condition
let(:status) { :hungry }
# and the expectation under the test condition
it 'says nyaaaan' do
expect(subject).to eq('nyaaaan')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment