Skip to content

Instantly share code, notes, and snippets.

@bricker
Forked from anonymous/mock_test_spec.rb
Last active August 29, 2015 14:14
Show Gist options
  • Save bricker/318f78e10e2d63f3f79d to your computer and use it in GitHub Desktop.
Save bricker/318f78e10e2d63f3f79d to your computer and use it in GitHub Desktop.
require 'spec_helper'
shared_examples "extended_definition" do
it "must contain original definition" do
expect(sense.extended_definition).to include(sense.definition)
end
it "must contain both sample texts" do
expect(
sense.samples.pluck(:sample).collect { |t| sense.extended_definition.include? t }.inject(:&)
).to be_truthy
end
end
describe WordSense do
context "dictionary word 'test'" do
let(:sense) { Word.find_by_name('test').senses.first }
include_examples 'extended_definition'
end
context "mocked word 'fnord'" do
let(:sense) { instance_double('WordSense', :definition => 'original definition') }
before do
sense.samples << instance_double('WordSampleDefinition', :sample => 'first sample definition')
sense.samples << instance_double('WordSampleDefinition', :sample => 'second sample definition')
end
include_examples 'extended_definition'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment