Created
May 10, 2013 05:37
-
-
Save lengarvey/5552601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Post do | |
describe 'validations' do | |
subject(:post) { Post.new } # sets the subject of this describe block | |
before { post.valid? } # runs a precondition for the test/s | |
[:title, :body].each do |attribute| | |
it "should validate presence of #{attribute}" do | |
expect(post).to have_at_least(1).error_on(attribute) | |
expect(post.errors.messages[attribute]).to include "can't be blank" | |
end | |
end | |
end | |
describe '#content' do | |
# Create a double of the MarkdownService | |
let(:markdown_service) { double('MarkdownService') } | |
before do | |
# We don't want to use the actual MarkdownService | |
# since it's tested elsewhere! | |
MarkdownService.stub(:new) { markdown_service } | |
end | |
it 'should convert its body to markdown' do | |
markdown_service.should_receive(:render).with('post body') | |
Post.new(:body => 'post body').content | |
end | |
end | |
describe '#author_name' do | |
context 'when the author exists' do | |
let(:author) { AdminUser.new } | |
subject { Post.new(:author => author).author_name } | |
before { author.stub(:name) { "Jane Smith" } } | |
it { should eq "Jane Smith" } | |
end | |
context 'when the author doesnt exist' do | |
subject { Post.new.author_name } | |
it { should eq "Nobody" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment