replace stub and mock deprecations with doubles

This commit is contained in:
Jonne Haß 2014-01-06 20:15:59 +01:00
parent b5854d3172
commit 32b9caa08c
47 changed files with 173 additions and 173 deletions

View file

@ -95,7 +95,7 @@ describe AdminsController do
end
it 'invites a new user' do
EmailInviter.should_receive(:new).and_return(stub.as_null_object)
EmailInviter.should_receive(:new).and_return(double.as_null_object)
get :admin_inviter, :identifier => 'bob@moms.com'
response.should redirect_to user_search_path
flash.notice.should include("invitation sent")

View file

@ -48,7 +48,7 @@ describe InvitationsController do
end
it 'creates an InviteEmail worker' do
inviter = stub(:emails => [@emails], :send! => true)
inviter = double(:emails => [@emails], :send! => true)
Workers::Mail::InviteEmail.should_receive(:perform_async).with(@invite['email_inviter']['emails'], @user.id, @invite['email_inviter'])
post :create, @invite
end
@ -98,7 +98,7 @@ describe InvitationsController do
end
it 'creates an InviteEmail worker' do
inviter = stub(:emails => [@emails], :send! => true)
inviter = double(:emails => [@emails], :send! => true)
Workers::Mail::InviteEmail.should_receive(:perform_async).with(@valid_emails, @user.id, @invite['email_inviter'])
post :create, @invite
end

View file

@ -11,7 +11,7 @@ describe ProfilesController do
describe '#show' do
let(:mock_person) {mock_model(User)}
let(:mock_presenter) { mock(:as_json => {:rock_star => "Jamie Cai"})}
let(:mock_presenter) { double(:as_json => {:rock_star => "Jamie Cai"})}
it "returns a post Presenter" do
Person.should_receive(:find_by_guid!).with("12345").and_return(mock_person)
@ -22,7 +22,7 @@ describe ProfilesController do
end
end
describe '#edit' do
describe '#edit' do
it 'succeeds' do
get :edit
response.should be_success
@ -77,12 +77,12 @@ describe ProfilesController do
put :update, params
eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set
end
it 'sets plaintext tags' do
params = { :id => eve.person.id,
:tags => ',#apples,#oranges,',
:profile => {:tag_string => '#pears'} }
put :update, params
eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'pears'].to_set
end
@ -91,7 +91,7 @@ describe ProfilesController do
params = { :id => eve.person.id,
:tags => ',#apples,#oranges,',
:profile => {:tag_string => 'bananas'} }
put :update, params
eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'bananas'].to_set
end

View file

@ -30,7 +30,7 @@ describe ShareVisibilitiesController do
@controller.params[:post_id] = id
@controller.params[:shareable_type] = 'Post'
Post.should_receive(:where).with(hash_including(:id => id)).once.and_return(stub.as_null_object)
Post.should_receive(:where).with(hash_including(:id => id)).once.and_return(double.as_null_object)
2.times do |n|
@controller.send(:accessible_post)
end

View file

@ -14,19 +14,19 @@ describe InterimStreamHackinessHelper do
def user_signed_in?
false
end
commenting_disabled?(stub).should == true
commenting_disabled?(double).should == true
end
it 'returns true if @commenting_disabled is set' do
@commenting_disabled = true
commenting_disabled?(stub).should == true
commenting_disabled?(double).should == true
@commenting_disabled = false
commenting_disabled?(stub).should == false
commenting_disabled?(double).should == false
end
it 'returns @stream.can_comment? if @stream is set' do
post = stub
@stream = stub
post = double
@stream = double
@stream.should_receive(:can_comment?).with(post).and_return(true)
commenting_disabled?(post).should == false

View file

@ -34,7 +34,7 @@ describe NotificationsHelper do
@ilya = FactoryGirl.create(:person)
@ilya.profile.first_name = 'ilya'
@ilya.profile.last_name = 'zhit'
@note = mock()
@note = double()
end
it 'with two, does not comma seperate two actors' do

View file

@ -14,7 +14,7 @@ describe PostsHelper do
context 'with posts with text' do
context 'when :length is passed in parameters' do
it 'returns string of size less or equal to :length' do
@sm = stub(:text => "## My title\n Post content...")
@sm = double(:text => "## My title\n Post content...")
string_size = 12
post_page_title(@sm, :length => string_size ).size.should <= string_size
end
@ -22,17 +22,17 @@ describe PostsHelper do
context 'when :length is not passed in parameters' do
context 'with a Markdown header of less than 200 characters on first line'do
it 'returns atx style header' do
@sm = stub(:text => "## My title\n Post content...")
@sm = double(:text => "## My title\n Post content...")
post_page_title(@sm).should == "## My title"
end
it 'returns setext style header' do
@sm = stub(:text => "My title \n======\n Post content...")
@sm = double(:text => "My title \n======\n Post content...")
post_page_title(@sm).should == "My title \n======"
end
end
context 'without a Markdown header of less than 200 characters on first line 'do
it 'truncates posts to the 20 first characters' do
@sm = stub(:text => "Very, very, very long post")
@sm = double(:text => "Very, very, very long post")
post_page_title(@sm).should == "Very, very, very ..."
end
end

View file

@ -12,7 +12,7 @@ describe "Dispatching" do
inlined_jobs do
# Luke now retracts his comment
Postzord::Dispatcher::Public.should_not_receive(:new)
Postzord::Dispatcher::Private.should_receive(:new).and_return(stub(:post => true))
Postzord::Dispatcher::Private.should_receive(:new).and_return(double(:post => true))
luke.retract(comment)
end
end

View file

@ -225,7 +225,7 @@ describe 'a user receives a post' do
Profile.where(:person_id => remote_person.id).delete_all
remote_person.attributes.delete(:id) # leaving a nil id causes it to try to save with id set to NULL in postgres
m = mock()
m = double()
Webfinger.should_receive(:new).twice.with(eve.person.diaspora_handle).and_return(m)
m.should_receive(:fetch).twice.and_return{
remote_person.save(:validate => false)

View file

@ -72,9 +72,9 @@ describe AccountDeleter do
describe "#delete_standard_user_associations" do
it 'removes all standard user associaltions' do
@account_deletion.normal_ar_user_associates_to_delete.each do |asso|
association_mock = mock
association_mock.should_receive(:delete)
bob.should_receive(asso).and_return([association_mock])
association_double = double
association_double.should_receive(:delete)
bob.should_receive(asso).and_return([association_double])
end
@account_deletion.delete_standard_user_associations
@ -87,9 +87,9 @@ describe AccountDeleter do
end
it 'removes all standard person associaltions' do
@account_deletion.normal_ar_person_associates_to_delete.each do |asso|
association_mock = mock
association_mock.should_receive(:delete_all)
bob.person.should_receive(asso).and_return(association_mock)
association_double = double
association_double.should_receive(:delete_all)
bob.person.should_receive(asso).and_return(association_double)
end
@account_deletion.delete_standard_person_associations
@ -98,7 +98,7 @@ describe AccountDeleter do
describe "#disassociate_invitations" do
it "sets invitations_from_me to be admin invitations" do
invites = [mock]
invites = [double]
bob.stub(:invitations_from_me).and_return(invites)
invites.first.should_receive(:convert_to_admin!)
@account_deletion.disassociate_invitations
@ -115,7 +115,7 @@ describe AccountDeleter do
describe '#delete_contacts_of_me' do
it 'deletes all the local contact objects where deleted account is the person' do
contacts = mock
contacts = double
Contact.should_receive(:all_contacts_of_person).with(bob.person).and_return(contacts)
contacts.should_receive(:destroy_all)
@account_deletion.delete_contacts_of_me
@ -135,7 +135,7 @@ describe AccountDeleter do
end
describe "#remove_conversation_visibilities" do
it "removes the conversation visibility for the deleted user" do
vis = stub
vis = double
ConversationVisibility.should_receive(:where).with(hash_including(:person_id => bob.person.id)).and_return(vis)
vis.should_receive(:destroy_all)
@account_deletion.remove_conversation_visibilities
@ -145,7 +145,7 @@ describe AccountDeleter do
describe "#remove_person_share_visibilities" do
it 'removes the share visibilities for a person ' do
@s_vis = stub
@s_vis = double
ShareVisibility.should_receive(:for_contacts_of_a_person).with(bob.person).and_return(@s_vis)
@s_vis.should_receive(:destroy_all)
@ -155,7 +155,7 @@ describe AccountDeleter do
describe "#remove_share_visibilities_by_contacts_of_user" do
it 'removes the share visibilities for a user' do
@s_vis = stub
@s_vis = double
ShareVisibility.should_receive(:for_a_users_contacts).with(bob).and_return(@s_vis)
@s_vis.should_receive(:destroy_all)

View file

@ -44,7 +44,7 @@ describe Configuration::Methods do
describe "#bare_pod_uri" do
it 'is #pod_uri.authority stripping www.' do
pod_uri = mock
pod_uri = double
@settings.stub(:pod_uri).and_return(pod_uri)
pod_uri.should_receive(:authority).and_return("www.example.org")
@settings.bare_pod_uri.should == 'example.org'
@ -53,10 +53,10 @@ describe Configuration::Methods do
describe "#configured_services" do
it "includes the enabled services only" do
services = mock
enabled = mock
services = double
enabled = double
enabled.stub(:enable?).and_return(true)
disabled = mock
disabled = double
disabled.stub(:enable?).and_return(false)
services.stub(:twitter).and_return(enabled)
services.stub(:tumblr).and_return(enabled)
@ -72,7 +72,7 @@ describe Configuration::Methods do
describe "#version_string" do
before do
@version = mock
@version = double
@version.stub(:number).and_return("0.0.0.0")
@version.stub(:release?).and_return(true)
@settings.stub(:version).and_return(@version)
@ -148,7 +148,7 @@ describe Configuration::Methods do
context "with a relative log set" do
it "joins that with Rails.root" do
path = "/some/path/"
Rails.stub(:root).and_return(stub(join: path))
Rails.stub(:root).and_return(double(join: path))
@settings.environment.sidekiq.log = "relative_path"
@settings.sidekiq_log.should match path
end

View file

@ -34,7 +34,7 @@ describe RelayableRetraction do
describe '#subscribers' do
it 'delegates it to target' do
arg = mock()
arg = double()
@retraction.target.should_receive(:subscribers).with(arg)
@retraction.subscribers(arg)
end
@ -67,7 +67,7 @@ describe RelayableRetraction do
end
it 'dispatches' do
zord = mock()
zord = double()
zord.should_receive(:post)
Postzord::Dispatcher.should_receive(:build).with(@local_luke, @retraction).and_return zord
@retraction.receive(@recipient, @comment.author)

View file

@ -13,7 +13,7 @@ describe SignedRetraction do
onward_retraction = retraction.dup
retraction.should_receive(:dup).and_return(onward_retraction)
dis = mock
dis = double
Postzord::Dispatcher.should_receive(:build).with(@resharer, onward_retraction).and_return(dis)
dis.should_receive(:post)
@ -34,7 +34,7 @@ describe SignedRetraction do
remote_retraction.dup.perform(bob)
Post.exists?(:id => remote_post.id).should be_false
dis = mock
dis = double
Postzord::Dispatcher.should_receive(:build){ |sender, retraction|
sender.should == alice
retraction.sender.should == alice.person

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe EmailInviter do
before do
@user = stub(:invitation_code => 'coolcodebro', :present? => true,
@user = double(:invitation_code => 'coolcodebro', :present? => true,
:email => 'foo@bar.com')
@emails = "mbs333@gmail.com, foo1@bar.com maxwell@dude.com"
end

View file

@ -7,7 +7,7 @@ require 'spec_helper'
describe HydraWrapper do
before do
@people = ["person", "person2", "person3"]
@wrapper = HydraWrapper.new stub, @people, "<encoded_xml>", stub
@wrapper = HydraWrapper.new double, @people, "<encoded_xml>", double
end
describe 'initialize' do
@ -25,7 +25,7 @@ describe HydraWrapper do
describe '#run' do
it 'delegates #run to the @hydra' do
hydra = stub.as_null_object
hydra = double.as_null_object
@wrapper.instance_variable_set :@hydra, hydra
hydra.should_receive :run
@wrapper.run
@ -58,7 +58,7 @@ describe HydraWrapper do
it 'inserts a job for every group of people' do
Base64.stub(:decode64)
@wrapper.dispatcher_class = stub salmon: stub(xml_for: "<XML>")
@wrapper.dispatcher_class = double salmon: double(xml_for: "<XML>")
@wrapper.stub(:grouped_people).and_return('https://foo.com' => @wrapper.people)
@wrapper.people.should_receive(:first).once
@wrapper.should_receive(:insert_job).with('https://foo.com', "<XML>", @wrapper.people).once
@ -67,8 +67,8 @@ describe HydraWrapper do
it 'does not insert a job for a person whos xml returns false' do
Base64.stub(:decode64)
@wrapper.stub(:grouped_people).and_return('https://foo.com' => [stub])
@wrapper.dispatcher_class = stub salmon: stub(xml_for: false)
@wrapper.stub(:grouped_people).and_return('https://foo.com' => [double])
@wrapper.dispatcher_class = double salmon: double(xml_for: false)
@wrapper.should_not_receive :insert_job
@wrapper.enqueue_batch
end
@ -77,15 +77,15 @@ describe HydraWrapper do
describe '#redirecting_to_https?!' do
it 'does not execute unless response has a 3xx code' do
resp = stub code: 200
resp = double code: 200
@wrapper.send(:redirecting_to_https?, resp).should be_false
end
it "returns true if just the protocol is different" do
host = "the-same.com/"
resp = stub(
request: stub(url: "http://#{host}"),
code: 302,
resp = double(
request: double(url: "http://#{host}"),
code: 302,
headers_hash: {
'Location' => "https://#{host}"
}
@ -96,8 +96,8 @@ describe HydraWrapper do
it "returns false if not just the protocol is different" do
host = "the-same.com/"
resp = stub(
request: stub(url: "http://#{host}"),
resp = double(
request: double(url: "http://#{host}"),
code: 302,
headers_hash: {
'Location' => "https://not-the-same/"

View file

@ -203,7 +203,7 @@ describe Postzord::Dispatcher do
@remote_people = []
@remote_people << alice.person
@mailman = Postzord::Dispatcher.build(alice, @sm)
@hydra = mock()
@hydra = double()
Typhoeus::Hydra.stub(:new).and_return(@hydra)
end
@ -318,7 +318,7 @@ describe Postzord::Dispatcher do
Workers::DeletePostFromService.should_receive(:perform_async).with(anything, anything)
mailman.post
end
end
describe '#and_notify_local_users' do

View file

@ -23,12 +23,12 @@ describe Postzord::Receiver::Private do
end
it 'valid for remote' do
salmon_mock = mock()
web_mock = mock()
web_mock.should_receive(:fetch).and_return true
salmon_mock.should_receive(:author_id).and_return(true)
Salmon::EncryptedSlap.should_receive(:from_xml).with(@salmon_xml, bob).and_return(salmon_mock)
Webfinger.should_receive(:new).and_return(web_mock)
salmon_double = double()
web_double = double()
web_double.should_receive(:fetch).and_return true
salmon_double.should_receive(:author_id).and_return(true)
Salmon::EncryptedSlap.should_receive(:from_xml).with(@salmon_xml, bob).and_return(salmon_double)
Webfinger.should_receive(:new).and_return(web_double)
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => @salmon_xml)
zord.instance_variable_get(:@user).should_not be_nil

View file

@ -84,7 +84,7 @@ describe Postzord::Receiver::Public do
describe '#recipient_user_ids' do
it 'calls User.all_sharing_with_person' do
User.should_receive(:all_sharing_with_person).and_return(stub(:select => []))
User.should_receive(:all_sharing_with_person).and_return(double(:select => []))
receiver = Postzord::Receiver::Public.new(@xml)
receiver.perform!
end
@ -101,7 +101,7 @@ describe Postzord::Receiver::Public do
end
it 'receives only for the parent author if he is local to the pod' do
comment = stub.as_null_object
comment = double.as_null_object
@receiver.instance_variable_set(:@object, comment)
comment.should_receive(:receive)
@ -109,10 +109,10 @@ describe Postzord::Receiver::Public do
end
it 'calls notifiy_users' do
comment = stub.as_null_object
comment = double.as_null_object
@receiver.instance_variable_set(:@object, comment)
local_batch_receiver = stub.as_null_object
local_batch_receiver = double.as_null_object
Postzord::Receiver::LocalBatch.stub(:new).and_return(local_batch_receiver)
local_batch_receiver.should_receive(:notify_users)
@receiver.receive_relayable

View file

@ -23,7 +23,7 @@ describe RakeHelpers do
it 'should send emails to each email' do
EmailInviter.should_receive(:new).exactly(3).times.and_return(stub.as_null_object)
EmailInviter.should_receive(:new).exactly(3).times.and_return(double.as_null_object)
process_emails(@csv, 100, 1, false)
end
end

View file

@ -7,7 +7,7 @@ require 'spec_helper'
describe Stream::Aspect do
describe '#aspects' do
it 'queries the user given initialized aspect ids' do
alice = stub.as_null_object
alice = double.as_null_object
stream = Stream::Aspect.new(alice, [1,2,3])
alice.aspects.should_receive(:where)
@ -15,7 +15,7 @@ describe Stream::Aspect do
end
it "returns all the user's aspects if no aspect ids are specified" do
alice = stub.as_null_object
alice = double.as_null_object
stream = Stream::Aspect.new(alice, [])
alice.aspects.should_not_receive(:where)
@ -23,7 +23,7 @@ describe Stream::Aspect do
end
it 'filters aspects given a user' do
alice = stub(:aspects => [stub(:id => 1)])
alice = double(:aspects => [double(:id => 1)])
alice.aspects.stub(:where).and_return(alice.aspects)
stream = Stream::Aspect.new(alice, [1,2,3])
@ -33,8 +33,8 @@ describe Stream::Aspect do
describe '#aspect_ids' do
it 'maps ids from aspects' do
alice = stub.as_null_object
aspects = stub.as_null_object
alice = double.as_null_object
aspects = double.as_null_object
stream = Stream::Aspect.new(alice, [1,2])
@ -46,39 +46,39 @@ describe Stream::Aspect do
describe '#posts' do
before do
@alice = stub.as_null_object
@alice = double.as_null_object
end
it 'calls visible posts for the given user' do
stream = Stream::Aspect.new(@alice, [1,2])
@alice.should_receive(:visible_shareables).and_return(stub.as_null_object)
@alice.should_receive(:visible_shareables).and_return(double.as_null_object)
stream.posts
end
it 'is called with 2 types' do
stream = Stream::Aspect.new(@alice, [1,2], :order => 'created_at')
@alice.should_receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare'])).and_return(stub.as_null_object)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:type=> ['StatusMessage', 'Reshare'])).and_return(double.as_null_object)
stream.posts
end
it 'respects ordering' do
stream = Stream::Aspect.new(@alice, [1,2], :order => 'created_at')
@alice.should_receive(:visible_shareables).with(Post, hash_including(:order => 'created_at DESC')).and_return(stub.as_null_object)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:order => 'created_at DESC')).and_return(double.as_null_object)
stream.posts
end
it 'respects max_time' do
stream = Stream::Aspect.new(@alice, [1,2], :max_time => 123)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:max_time => instance_of(Time))).and_return(stub.as_null_object)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:max_time => instance_of(Time))).and_return(double.as_null_object)
stream.posts
end
it 'passes for_all_aspects to visible posts' do
stream = Stream::Aspect.new(@alice, [1,2], :max_time => 123)
all_aspects = mock
all_aspects = double
stream.stub(:for_all_aspects?).and_return(all_aspects)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:all_aspects? => all_aspects)).and_return(stub.as_null_object)
@alice.should_receive(:visible_shareables).with(Post, hash_including(:all_aspects? => all_aspects)).and_return(double.as_null_object)
stream.posts
end
end
@ -87,19 +87,19 @@ describe Stream::Aspect do
it 'should call Person.all_from_aspects' do
class Person ; end
alice = stub.as_null_object
alice = double.as_null_object
aspect_ids = [1,2,3]
stream = Stream::Aspect.new(alice, [])
stream.stub(:aspect_ids).and_return(aspect_ids)
Person.should_receive(:unique_from_aspects).with(stream.aspect_ids, alice).and_return(stub(:includes => :profile))
Person.should_receive(:unique_from_aspects).with(stream.aspect_ids, alice).and_return(double(:includes => :profile))
stream.people
end
end
describe '#aspect' do
before do
alice = stub.as_null_object
alice = double.as_null_object
@stream = Stream::Aspect.new(alice, [1,2])
end
@ -116,7 +116,7 @@ describe Stream::Aspect do
describe 'for_all_aspects?' do
before do
alice = stub.as_null_object
alice = double.as_null_object
alice.aspects.stub(:size).and_return(2)
@stream = Stream::Aspect.new(alice, [1,2])
end

View file

@ -14,7 +14,7 @@ describe Stream::Base do
describe '#stream_posts' do
it "should returns the posts.for_a_stream" do
posts = mock
posts = double
@stream.stub(:posts).and_return(posts)
@stream.stub(:like_posts_for_stream!)
@ -70,7 +70,7 @@ describe Stream::Base do
describe '#people' do
it 'excludes blocked people' do
@stream.should_receive(:stream_posts).and_return(stub.as_null_object)
@stream.should_receive(:stream_posts).and_return(double.as_null_object)
@stream.people
end
end

View file

@ -16,7 +16,7 @@ describe Stream::Multi do
.with(alice, 'updated_at', @stream.max_time,
AppConfig.settings.community_spotlight.enable? &&
alice.show_community_spotlight_in_stream?)
.and_return(mock.tap { |m| m.stub(:make_relation!)})
.and_return(double.tap { |m| m.stub(:make_relation!)})
@stream.posts
end
end

View file

@ -104,7 +104,7 @@ describe Webfinger do
describe 'cached_person' do
it 'sets the person by looking up the account from Person.by_account_identifier' do
person = stub
person = double
Person.should_receive(:by_account_identifier).with(account).and_return(person)
finger.cached_person.should == person
finger.person.should == person

View file

@ -22,7 +22,7 @@ describe AccountDeletion do
end
it 'creates a deleter' do
AccountDeleter.should_receive(:new).with(alice.person.diaspora_handle).and_return(stub(:perform! => true))
AccountDeleter.should_receive(:new).with(alice.person.diaspora_handle).and_return(double(:perform! => true))
@ad.perform!
end
@ -45,7 +45,7 @@ describe AccountDeletion do
end
it 'creates a public postzord' do
Postzord::Dispatcher::Public.should_receive(:new).and_return(stub.as_null_object)
Postzord::Dispatcher::Public.should_receive(:new).and_return(double.as_null_object)
@ad = AccountDeletion.new(:person => alice.person)
@ad.send(:dispatch)
end

View file

@ -186,7 +186,7 @@ describe Contact do
describe '#dispatch_request' do
it 'pushes to people' do
@contact.stub(:user).and_return(@user)
m = mock()
m = double()
m.should_receive(:post)
Postzord::Dispatcher.should_receive(:build).and_return(m)
@contact.dispatch_request

View file

@ -492,7 +492,7 @@ describe Person do
describe '.url_batch_update' do
it "calls #update_person_url given an array of users and a url" do
people = [stub.as_null_object, stub.as_null_object, stub.as_null_object]
people = [double.as_null_object, double.as_null_object, double.as_null_object]
people.each do |person|
person.should_receive(:update_url).with(@url)
end

View file

@ -54,9 +54,9 @@ describe Photo do
end
it 'sets the random prefix' do
photo_stub = stub.as_null_object
photo_stub.should_receive(:random_string=)
Photo.stub(:new).and_return(photo_stub)
photo_double = double.as_null_object
photo_double.should_receive(:random_string=)
Photo.stub(:new).and_return(photo_double)
Photo.diaspora_initialize(
:author => @user.person, :user_file => @image)
@ -73,9 +73,9 @@ describe Photo do
it 'saves the photo' do
url = "https://service.com/user/profile_image"
photo_stub = stub.as_null_object
photo_stub.should_receive(:remote_unprocessed_image_url=).with(url)
Photo.stub(:new).and_return(photo_stub)
photo_double = double.as_null_object
photo_double.should_receive(:remote_unprocessed_image_url=).with(url)
Photo.stub(:new).and_return(photo_double)
Photo.diaspora_initialize(
:author => @user.person, :image_url => url)

View file

@ -50,19 +50,19 @@ describe Post do
describe '.for_a_stream' do
it 'calls #for_visible_shareable_sql' do
time, order = stub, stub
time, order = double, double
Post.should_receive(:for_visible_shareable_sql).with(time, order).and_return(Post)
Post.for_a_stream(time, order)
end
it 'calls includes_for_a_stream' do
Post.should_receive(:includes_for_a_stream)
Post.for_a_stream(stub, stub)
Post.for_a_stream(double, double)
end
it 'calls excluding_blocks if a user is present' do
Post.should_receive(:excluding_blocks).with(alice).and_return(Post)
Post.for_a_stream(stub, stub, alice)
Post.for_a_stream(double, double, alice)
end
end
@ -141,7 +141,7 @@ describe Post do
end
it 'defaults to 15 posts' do
chain = stub.as_null_object
chain = double.as_null_object
Post.stub(:by_max_time).and_return(chain)
chain.should_receive(:limit).with(15).and_return(Post)
@ -255,7 +255,7 @@ describe Post do
before do
@post = FactoryGirl.create(:status_message, :author => bob.person)
@known_post = Post.new
bob.stub(:contact_for).with(eve.person).and_return(stub(:receive_shareable => true))
bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true))
end
context "user knows about the post" do
@ -287,7 +287,7 @@ describe Post do
end
it 'notifies the user if they are mentioned' do
bob.stub(:contact_for).with(eve.person).and_return(stub(:receive_shareable => true))
bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true))
bob.should_receive(:notify_if_mentioned).and_return(true)
@post.send(:receive_persisted, bob, eve.person, @known_post).should == true
@ -304,12 +304,12 @@ describe Post do
end
it "it receives the post from the contact of the author" do
bob.should_receive(:contact_for).with(eve.person).and_return(stub(:receive_shareable => true))
bob.should_receive(:contact_for).with(eve.person).and_return(double(:receive_shareable => true))
@post.send(:receive_non_persisted, bob, eve.person).should == true
end
it 'notifies the user if they are mentioned' do
bob.stub(:contact_for).with(eve.person).and_return(stub(:receive_shareable => true))
bob.stub(:contact_for).with(eve.person).and_return(double(:receive_shareable => true))
bob.should_receive(:notify_if_mentioned).and_return(true)
@post.send(:receive_non_persisted, bob, eve.person).should == true
@ -383,20 +383,20 @@ describe Post do
it "looks up on the passed user object if it's non-nil" do
post = FactoryGirl.create :status_message
user = mock
user = double
user.should_receive(:find_visible_shareable_by_id).with(Post, post.id, key: :id).and_return(post)
Post.find_by_guid_or_id_with_user post.id, user
end
it "raises ActiveRecord::RecordNotFound with a non-existing id and a user" do
user = stub(find_visible_shareable_by_id: nil)
user = double(find_visible_shareable_by_id: nil)
expect {
Post.find_by_guid_or_id_with_user 123, user
}.to raise_error ActiveRecord::RecordNotFound
end
it "raises Diaspora::NonPublic for a non-existing id without a user" do
Post.stub where: stub(includes: stub(first: nil))
Post.stub where: double(includes: double(first: nil))
expect {
Post.find_by_guid_or_id_with_user 123
}.to raise_error Diaspora::NonPublic

View file

@ -143,7 +143,7 @@ describe Reshare do
before do
@root_object = @reshare.root
@root_object.delete
@response = mock
@response = double
@response.stub(:status).and_return(200)
@response.stub(:success?).and_return(true)
end
@ -156,9 +156,9 @@ describe Reshare do
@original_author.profile = @original_profile
wf_prof_mock = mock
wf_prof_mock.should_receive(:fetch).and_return(@original_author)
Webfinger.should_receive(:new).and_return(wf_prof_mock)
wf_prof_double = double
wf_prof_double.should_receive(:fetch).and_return(@original_author)
Webfinger.should_receive(:new).and_return(wf_prof_double)
@response.stub(:body).and_return(@root_object.to_diaspora_xml)
@ -216,9 +216,9 @@ describe Reshare do
different_person = FactoryGirl.build(:person)
wf_prof_mock = mock
wf_prof_mock.should_receive(:fetch).and_return(different_person)
Webfinger.should_receive(:new).and_return(wf_prof_mock)
wf_prof_double = double
wf_prof_double.should_receive(:fetch).and_return(different_person)
Webfinger.should_receive(:new).and_return(wf_prof_double)
different_person.stub(:url).and_return(@original_author.url)

View file

@ -26,14 +26,14 @@ describe Services::Facebook do
it 'removes text formatting markdown from post text' do
message = "Text with some **bolded** and _italic_ parts."
post = stub(:text => message, :photos => [])
post = double(:text => message, :photos => [])
post_params = @service.create_post_params(post)
post_params[:message].should match "Text with some bolded and italic parts."
end
it 'does not add post link when no photos' do
message = "Text with some **bolded** and _italic_ parts."
post = stub(:text => message, :photos => [])
post = double(:text => message, :photos => [])
post_params = @service.create_post_params(post)
post_params[:message].should match "Text with some bolded and italic parts."
end

View file

@ -11,12 +11,12 @@ describe Services::Tumblr do
describe '#post' do
it 'posts a status message to tumblr and saves the returned ids' do
response = mock(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}')
response = double(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}')
OAuth::AccessToken.any_instance.should_receive(:get)
.with("/v2/user/info")
.and_return(response)
response = mock(code: "201", body: '{"response": {"id": "bla"}}')
response = double(code: "201", body: '{"response": {"id": "bla"}}')
OAuth::AccessToken.any_instance.should_receive(:post)
.with("/v2/blog/foo.tumblr.com/post", @service.build_tumblr_post(@post, ''))
.and_return(response)

View file

@ -39,7 +39,7 @@ describe Services::Twitter do
it 'removes text formatting markdown from post text' do
message = "Text with some **bolded** and _italic_ parts."
post = stub(:text => message, :photos => [])
post = double(:text => message, :photos => [])
@service.send(:build_twitter_post, post).should match "Text with some bolded and italic parts."
end
@ -53,19 +53,19 @@ describe Services::Twitter do
it "should not truncate a short message" do
short_message = SecureRandom.hex(20)
short_post = stub(:text => short_message, :photos => [])
short_post = double(:text => short_message, :photos => [])
@service.send(:build_twitter_post, short_post).should match short_message
end
it "should truncate a long message" do
long_message = SecureRandom.hex(220)
long_post = stub(:text => long_message, :id => 1, :photos => [])
long_post = double(:text => long_message, :id => 1, :photos => [])
@service.send(:build_twitter_post, long_post).length.should be < long_message.length
end
it "should not truncate a long message with an http url" do
long_message = " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + @long_message_end
long_post = stub(:text => long_message, :id => 1, :photos => [])
long_post = double(:text => long_message, :id => 1, :photos => [])
@post.text = long_message
answer = @service.send(:build_twitter_post, @post)
@ -74,7 +74,7 @@ describe Services::Twitter do
it "should not cut links when truncating a post" do
long_message = SecureRandom.hex(40) + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + SecureRandom.hex(55)
long_post = stub(:text => long_message, :id => 1, :photos => [])
long_post = double(:text => long_message, :id => 1, :photos => [])
answer = @service.send(:build_twitter_post, long_post)
answer.should match /\.\.\./
@ -83,7 +83,7 @@ describe Services::Twitter do
it "should append the otherwise-cut link when truncating a post" do
long_message = "http://joindiaspora.com/a-very-long-decoy-url.html " + SecureRandom.hex(20) + " http://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + SecureRandom.hex(55) + " http://joindiaspora.com/a-very-long-decoy-url-part-2.html"
long_post = stub(:text => long_message, :id => 1, :photos => [])
long_post = double(:text => long_message, :id => 1, :photos => [])
answer = @service.send(:build_twitter_post, long_post)
answer.should match /\.\.\./
@ -99,7 +99,7 @@ describe Services::Twitter do
it "should truncate a long message with an ftp url" do
long_message = @long_message_start + " ftp://joindiaspora.com/a-very-long-url-name-that-will-be-shortened.html " + @long_message_end
long_post = stub(:text => long_message, :id => 1, :photos => [])
long_post = double(:text => long_message, :id => 1, :photos => [])
answer = @service.send(:build_twitter_post, long_post)
answer.should match /\.\.\./
@ -107,7 +107,7 @@ describe Services::Twitter do
it "should not truncate a message of maximum length" do
exact_size_message = SecureRandom.hex(70)
exact_size_post = stub(:text => exact_size_message, :id => 1, :photos => [])
exact_size_post = double(:text => exact_size_message, :id => 1, :photos => [])
answer = @service.send(:build_twitter_post, exact_size_post)
answer.should match exact_size_message
@ -138,9 +138,9 @@ describe Services::Twitter do
describe "#profile_photo_url" do
it 'returns the original profile photo url' do
user_stub = stub
user_stub.should_receive(:profile_image_url_https).with("original").and_return("http://a2.twimg.com/profile_images/uid/avatar.png")
Twitter::Client.any_instance.should_receive(:user).with("joindiaspora").and_return(user_stub)
user_double = double
user_double.should_receive(:profile_image_url_https).with("original").and_return("http://a2.twimg.com/profile_images/uid/avatar.png")
Twitter::Client.any_instance.should_receive(:user).with("joindiaspora").and_return(user_double)
@service.nickname = "joindiaspora"
@service.profile_photo_url.should == "http://a2.twimg.com/profile_images/uid/avatar.png"

View file

@ -63,7 +63,7 @@ describe User::Connecting do
end
it 'dispatches a retraction' do
p = mock()
p = double()
Postzord::Dispatcher.should_receive(:build).and_return(p)
p.should_receive(:post)
@ -155,7 +155,7 @@ describe User::Connecting do
end
it 'posts profile' do
m = mock()
m = double()
Postzord::Dispatcher.should_receive(:build).twice.and_return(m)
m.should_receive(:post).twice
alice.share_with(eve.person, alice.aspects.first)

View file

@ -94,7 +94,7 @@ describe User do
User.daily_actives.should_not include(user)
end
end
describe 'halfyear_actives' do
it 'returns list which includes users who latest signed in within half a year' do
user = FactoryGirl.build(:user)
@ -835,7 +835,7 @@ describe User do
describe '#retract' do
before do
@retraction = mock
@retraction = double
@post = FactoryGirl.build(:status_message, :author => bob.person, :public => true)
end
@ -846,7 +846,7 @@ describe User do
end
it 'sends a retraction' do
dispatcher = mock
dispatcher = double
Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, anything()).and_return(dispatcher)
dispatcher.should_receive(:post)
@ -858,7 +858,7 @@ describe User do
reshare = FactoryGirl.create(:reshare, :root => @post, :author => person)
@post.reshares << reshare
dispatcher = mock
dispatcher = double
Postzord::Dispatcher.should_receive(:build).with(bob, @retraction, {:additional_subscribers => [person], :services => anything}).and_return(dispatcher)
dispatcher.should_receive(:post)
@ -925,9 +925,9 @@ describe User do
AppConfig.settings.autofollow_on_join = true
AppConfig.settings.autofollow_on_join_user = 'one'
wf_mock = mock
wf_mock.should_receive(:fetch)
Webfinger.should_receive(:new).with('one').and_return(wf_mock)
wf_double = double
wf_double.should_receive(:fetch)
Webfinger.should_receive(:new).with('one').and_return(wf_double)
user.seed_aspects
end

View file

@ -67,13 +67,13 @@ describe PostPresenter do
context 'with posts with text' do
context 'with a Markdown header of less than 200 characters on first line'do
it 'returns atx style header' do
@sm = stub(:text => "## My title\n Post content...")
@sm = double(:text => "## My title\n Post content...")
@presenter.post = @sm
@presenter.title.should == "## My title"
end
it 'returns setext style header' do
@sm = stub(:text => "My title \n======\n Post content...")
@sm = double(:text => "My title \n======\n Post content...")
@presenter.post = @sm
@presenter.title.should == "My title \n======"
end
@ -81,7 +81,7 @@ describe PostPresenter do
context 'without a Markdown header of less than 200 characters on first line 'do
it 'truncates post to the 20 first characters' do
@sm = stub(:text => "Very, very, very long post")
@sm = double(:text => "Very, very, very long post")
@presenter.post = @sm
@presenter.title.should == "Very, very, very ..."
end
@ -90,7 +90,7 @@ describe PostPresenter do
context 'with posts without text' do
it ' displays a messaage with the post class' do
@sm = stub(:text => "", :author => bob.person, :author_name => bob.person.name)
@sm = double(:text => "", :author => bob.person, :author_name => bob.person.name)
@presenter.post = @sm
@presenter.title.should == "A post from #{@sm.author.name}"
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe ServicePresenter do
describe '#as_json' do
it 'includes the provider name of the json' do
presenter = ServicePresenter.new(stub(:provider => "fakebook"))
presenter = ServicePresenter.new(double(:provider => "fakebook"))
presenter.as_json[:provider].should == 'fakebook'
end
end

View file

@ -21,7 +21,7 @@ describe UserPresenter do
describe '#services' do
it 'provides an array of jsonifed services' do
fakebook = stub(:provider => 'fakebook')
fakebook = double(:provider => 'fakebook')
bob.stub(:services).and_return([fakebook])
@presenter.services.should include(:provider => 'fakebook')
end
@ -29,7 +29,7 @@ describe UserPresenter do
describe '#configured_services' do
it 'displays a list of the users configured services' do
fakebook = stub(:provider => 'fakebook')
fakebook = double(:provider => 'fakebook')
bob.stub(:services).and_return([fakebook])
@presenter.configured_services.should include("fakebook")
end

View file

@ -7,7 +7,7 @@ require 'spec_helper'
describe Workers::DeleteAccount do
describe '#perform' do
it 'performs the account deletion' do
account_deletion = stub
account_deletion = double
AccountDeletion.stub(:find).and_return(account_deletion)
account_deletion.should_receive(:perform!)

View file

@ -7,7 +7,7 @@ describe Workers::DeletePostFromService do
end
it 'calls service#delete_post with given service' do
m = mock()
m = double()
url = "foobar"
m.should_receive(:delete_post)
Service.stub(:find_by_id).and_return(m)

View file

@ -13,14 +13,14 @@ describe Workers::FetchProfilePhoto do
User.stub(:find).and_return(@user)
Service.stub(:find).and_return(@service)
@photo_stub = stub
@photo_stub.stub(:save!).and_return(true)
@photo_stub.stub(:url).and_return("image.jpg")
@photo_double = double
@photo_double.stub(:save!).and_return(true)
@photo_double.stub(:url).and_return("image.jpg")
end
it 'saves the profile image' do
@photo_stub.should_receive(:save!).and_return(true)
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_stub)
@photo_double.should_receive(:save!).and_return(true)
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_double)
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
end
@ -34,19 +34,19 @@ describe Workers::FetchProfilePhoto do
end
it "fetches fallback if it's provided" do
@photo_stub.should_receive(:save!).and_return(true)
@photo_double.should_receive(:save!).and_return(true)
@service.stub(:profile_photo_url).and_return(nil)
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_stub)
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_double)
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id, "https://service.com/fallback_lowres.jpg")
end
end
it 'updates the profile' do
@photo_stub.stub(:url).and_return("large.jpg", "medium.jpg", "small.jpg")
it 'updates the profile' do
@photo_double.stub(:url).and_return("large.jpg", "medium.jpg", "small.jpg")
Photo.should_receive(:diaspora_initialize).and_return(@photo_stub)
Photo.should_receive(:diaspora_initialize).and_return(@photo_double)
@user.should_receive(:update_profile).with(hash_including({
:image_url => "large.jpg",
:image_url_medium => "medium.jpg",

View file

@ -11,9 +11,9 @@ describe Workers::Mail::Mentioned do
sm = FactoryGirl.build(:status_message)
m = Mention.new(:person => user.person, :post=> sm)
mail_mock = mock()
mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock)
mail_double = double()
mail_double.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_double)
Workers::Mail::Mentioned.new.perform(user.id, sm.author.id, m.id)
end

View file

@ -17,9 +17,9 @@ describe Workers::Mail::PrivateMessage do
cnv = Conversation.create(create_hash)
message = cnv.messages.first
mail_mock = mock()
mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock)
mail_double = double()
mail_double.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_double)
Workers::Mail::Mentioned.new.perform(user2.id, user1.person.id, message.id)
end

View file

@ -10,9 +10,9 @@ describe Workers::Mail::Reshared do
sm = FactoryGirl.build(:status_message, :author => bob.person, :public => true)
reshare = FactoryGirl.build(:reshare, :author => alice.person, :root=> sm)
mail_mock = mock()
mail_mock.should_receive(:deliver)
Notifier.should_receive(:reshared).with(bob.id, reshare.author.id, reshare.id).and_return(mail_mock)
mail_double = double()
mail_double.should_receive(:deliver)
Notifier.should_receive(:reshared).with(bob.id, reshare.author.id, reshare.id).and_return(mail_double)
Workers::Mail::Reshared.new.perform(bob.id, reshare.author.id, reshare.id)
end

View file

@ -6,7 +6,7 @@ describe Workers::PostToService do
aspect = user.aspects.create(:name => "yeah")
post = user.post(:status_message, :text => 'foo', :to => aspect.id)
User.stub(:find_by_id).with(user.id.to_s).and_return(user)
m = mock()
m = double()
url = "foobar"
m.should_receive(:post).with(anything, url)
Service.stub(:find_by_id).and_return(m)

View file

@ -8,7 +8,7 @@ describe Workers::PublishToHub do
describe '.perform' do
it 'calls pubsubhubbub' do
url = "http://publiczone.com/"
m = mock()
m = double()
m.should_receive(:publish).with(url+'.atom')
Pubsubhubbub.should_receive(:new).with(AppConfig.environment.pubsub_server).and_return(m)

View file

@ -13,7 +13,7 @@ describe Workers::ReceiveEncryptedSalmon do
}
end
it 'calls receive_salmon' do
zord = mock
zord = double
zord.should_receive(:perform!)
Postzord::Receiver::Private.should_receive(:new).with(@user, hash_including(:salmon_xml => @xml)).and_return(zord)

View file

@ -15,9 +15,9 @@ describe Workers::Receive do
end
it 'calls receive' do
zord_mock = mock()
zord_mock.should_receive(:parse_and_receive).with(@xml)
Postzord::Receiver::Private.should_receive(:new).with(@user, anything).and_return(zord_mock)
zord_double = double()
zord_double.should_receive(:parse_and_receive).with(@xml)
Postzord::Receiver::Private.should_receive(:new).with(@user, anything).and_return(zord_double)
Workers::Receive.new.perform(@user.id, @xml, @person.id)
end
end