Created
February 10, 2014 14:38
-
-
Save workmaster2n/8917058 to your computer and use it in GitHub Desktop.
Mock Spec
This file contains hidden or 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
| class CategoryCacheClearer < Struct.new(:article) | |
| def call | |
| article.category_list = '' | |
| article.save | |
| end | |
| end | |
| describe CategoryCacheClearer do | |
| describe '#call' do | |
| let(:article) { mock(:save, :category_list=) } | |
| let(:category_cache_clearer) { CategoryCacheClearer.new(article) } | |
| it 'clears the category list' do | |
| article.should_receive(:category_list=) | |
| category_cache_clearer.call | |
| end | |
| it 'calls save on the article' do | |
| article.should_receive(:save) | |
| category_cache_clearer.call | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tend to use bourne to spy on behavior like this so it'd be more like this:
It just reverses the steps so that you're keeping the standard four phase test (setup, execute, assert, teardown). You also want to ensure that you're testing the full interface on outgoing command messages, so ensuring that you're doing
with('')is somewhat important.