master
1require 'rails_helper'
2
3RSpec.describe PublishToTwitterJob, :type => :job do
4 subject { PublishToTwitterJob.new }
5
6 describe "#perform" do
7 let(:artist) { User.new(name: 'joe') }
8 let(:cake) { Creation.new(id: 88, name: 'yummy', user: artist) }
9 let(:twitter) { double(tweet: '') }
10
11 before :each do
12 allow(subject).to receive(:twitter).and_return(twitter)
13 end
14
15 context "when the cake is published and safe for kids" do
16 before :each do
17 allow(cake).to receive(:published?).and_return(true)
18 end
19
20 it "tweets about the new cake" do
21 subject.perform(cake)
22 expect(twitter).to have_received(:tweet).
23 with("yummy By joe on http://www.example.com/cakes/88-yummy!")
24 end
25 end
26
27 context "when the cake is not published" do
28 before :each do
29 allow(cake).to receive(:published?).and_return(false)
30 end
31
32 it "should not publish any tweets" do
33 subject.perform(cake)
34 expect(twitter).not_to have_received(:tweet)
35 end
36 end
37 end
38end