do not overwrite rspec methods (receive)

This commit is contained in:
Jonne Haß 2014-01-06 18:18:10 +01:00
parent df0bff6537
commit 01ecd9d054
3 changed files with 22 additions and 23 deletions

View file

@ -5,7 +5,7 @@
require 'spec_helper' require 'spec_helper'
def receive(post, opts) def receive_post(post, opts)
sender = opts.fetch(:from) sender = opts.fetch(:from)
receiver = opts.fetch(:by) receiver = opts.fetch(:by)
salmon_xml = sender.salmon(post).xml_for(receiver.person) salmon_xml = sender.salmon(post).xml_for(receiver.person)
@ -36,7 +36,7 @@ def temporary_post(user, &block)
end end
def expect_error(partial_message, &block)# DOES NOT REQUIRE ERROR!! def expect_error(partial_message, &block)# DOES NOT REQUIRE ERROR!!
begin begin
yield yield
rescue => e rescue => e
e.message.should match partial_message e.message.should match partial_message
@ -58,7 +58,7 @@ end
#returns the message #returns the message
def legit_post_from_user1_to_user2(user1, user2) def legit_post_from_user1_to_user2(user1, user2)
original_message = user1.post(:status_message, :text => 'store this!', :to => user1.aspects.find_by_name("generic").id) original_message = user1.post(:status_message, :text => 'store this!', :to => user1.aspects.find_by_name("generic").id)
receive(original_message, :from => user1, :by => user2) receive_post(original_message, :from => user1, :by => user2)
original_message original_message
end end
@ -126,9 +126,9 @@ describe "attack vectors" do
expect { expect {
expect { expect {
receive(profile, :from => alice, :by => bob) receive_post(profile, :from => alice, :by => bob)
}.to raise_error Diaspora::AuthorXMLAuthorMismatch }.to raise_error Diaspora::AuthorXMLAuthorMismatch
}.to_not change(eve.profile, :first_name) }.to_not change(eve.profile, :first_name)
end end
end end
@ -153,7 +153,7 @@ describe "attack vectors" do
malicious_message = FactoryGirl.build(:status_message, :id => original_message.id, :guid => original_message.guid, :author => alice.person) malicious_message = FactoryGirl.build(:status_message, :id => original_message.id, :guid => original_message.guid, :author => alice.person)
expect{ expect{
receive(malicious_message, :from => alice, :by => bob) receive_post(malicious_message, :from => alice, :by => bob)
}.to_not change(original_message, :author_id) }.to_not change(original_message, :author_id)
end end
@ -166,7 +166,7 @@ describe "attack vectors" do
malicious_message = FactoryGirl.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => eve.person) malicious_message = FactoryGirl.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => eve.person)
expect { expect {
receive(malicious_message, :from => eve, :by => bob) receive_post(malicious_message, :from => eve, :by => bob)
}.to_not change(original_message, :text) }.to_not change(original_message, :text)
end end
end end
@ -175,14 +175,14 @@ describe "attack vectors" do
it "ignores retractions on a post not owned by the retraction's sender" do it "ignores retractions on a post not owned by the retraction's sender" do
original_message = legit_post_from_user1_to_user2(eve, bob) original_message = legit_post_from_user1_to_user2(eve, bob)
ret = bogus_retraction do |retraction| ret = bogus_retraction do |retraction|
retraction.post_guid = original_message.guid retraction.post_guid = original_message.guid
retraction.diaspora_handle = alice.person.diaspora_handle retraction.diaspora_handle = alice.person.diaspora_handle
retraction.type = original_message.class.to_s retraction.type = original_message.class.to_s
end end
expect { expect {
receive(ret, :from => alice, :by => bob) receive_post(ret, :from => alice, :by => bob)
}.to_not change(StatusMessage, :count) }.to_not change(StatusMessage, :count)
end end
@ -195,7 +195,7 @@ describe "attack vectors" do
end end
end end
expect{ expect{
receive(bogus_retraction, :from => alice, :by => bob) receive_post(bogus_retraction, :from => alice, :by => bob)
}.to_not raise_error }.to_not raise_error
end end
@ -210,7 +210,7 @@ describe "attack vectors" do
expect { expect {
expect { expect {
receive(retraction, :from => alice, :by => bob) receive_post(retraction, :from => alice, :by => bob)
}.to raise_error Diaspora::AuthorXMLAuthorMismatch }.to raise_error Diaspora::AuthorXMLAuthorMismatch
}.to_not change(bob.visible_shareables(Post), :count) }.to_not change(bob.visible_shareables(Post), :count)
@ -227,7 +227,7 @@ describe "attack vectors" do
end end
expect{ expect{
receive(retraction, :from => alice, :by => bob) receive_post(retraction, :from => alice, :by => bob)
}.to_not change{bob.reload.contacts.count} }.to_not change{bob.reload.contacts.count}
end end
@ -240,14 +240,14 @@ describe "attack vectors" do
expect{ expect{
expect { expect {
receive(retraction, :from => alice, :by => bob) receive_post(retraction, :from => alice, :by => bob)
}.to raise_error Diaspora::AuthorXMLAuthorMismatch }.to raise_error Diaspora::AuthorXMLAuthorMismatch
}.to_not change(bob.contacts, :count) }.to_not change(bob.contacts, :count)
end end
it 'does not let another user update other persons post' do it 'does not let another user update other persons post' do
original_message = eve.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => eves_aspect.id) original_message = eve.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => eves_aspect.id)
receive(original_message, :from => eve, :by => bob) receive_post(original_message, :from => eve, :by => bob)
#is this testing two things? #is this testing two things?
new_message = original_message.dup new_message = original_message.dup
@ -255,7 +255,7 @@ describe "attack vectors" do
new_message.text = "bad bad bad" new_message.text = "bad bad bad"
expect{ expect{
receive(new_message, :from => alice, :by => bob) receive_post(new_message, :from => alice, :by => bob)
}.to_not change(original_message, :text) }.to_not change(original_message, :text)
end end
end end

View file

@ -23,26 +23,27 @@ describe Reshare do
end end
describe "#receive" do describe "#receive" do
let(:receive) {@reshare.receive(@root.author.owner, @reshare.author)} let(:receive_reshare) { @reshare.receive(@root.author.owner, @reshare.author) }
before do before do
@reshare = FactoryGirl.create(:reshare, :root => FactoryGirl.build(:status_message, :author => bob.person, :public => true)) @reshare = FactoryGirl.create(:reshare, :root => FactoryGirl.build(:status_message, :author => bob.person, :public => true))
@root = @reshare.root @root = @reshare.root
end end
it 'increments the reshare count' do it 'increments the reshare count' do
receive receive_reshare
@root.resharers.count.should == 1 @root.resharers.count.should == 1
end end
it 'adds the resharer to the re-sharers of the post' do it 'adds the resharer to the re-sharers of the post' do
receive receive_reshare
@root.resharers.should include(@reshare.author) @root.resharers.should include(@reshare.author)
end end
it 'does not error if the root author has a contact for the resharer' do it 'does not error if the root author has a contact for the resharer' do
bob.share_with @reshare.author, bob.aspects.first bob.share_with @reshare.author, bob.aspects.first
proc { proc {
Timeout.timeout(5) do Timeout.timeout(5) do
receive #This doesn't ever terminate on my machine before it was fixed. receive_reshare #This doesn't ever terminate on my machine before it was fixed.
end end
}.should_not raise_error }.should_not raise_error
end end

View file

@ -2,8 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'rubygems'
prefork = proc do prefork = proc do
# Loading more in this block will cause your tests to run faster. However, # Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll # if you change any configuration or code from libraries loaded here, you'll
@ -13,7 +11,7 @@ prefork = proc do
#Spork.trap_method(Rails::Application::RoutesReloader, :reload!) #Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
require File.join(File.dirname(__FILE__), '..', 'config', 'environment') unless defined?(Rails) require File.join(File.dirname(__FILE__), '..', 'config', 'environment')
require Rails.root.join('spec', 'helper_methods') require Rails.root.join('spec', 'helper_methods')
require Rails.root.join('spec', 'spec-doc') require Rails.root.join('spec', 'spec-doc')
require 'rspec/rails' require 'rspec/rails'
@ -112,6 +110,6 @@ RSpec.configure do |config|
DeferredGarbageCollection.start DeferredGarbageCollection.start
end end
config.after(:all) do config.after(:all) do
DeferredGarbageCollection.reconsider DeferredGarbageCollection.reconsider
end end
end end