Skip to content

Instantly share code, notes, and snippets.

@cflipse
cflipse / stubbing_with_arguments_spec.rb
Created December 14, 2011 19:28 — forked from adomokos/stubbing_with_arguments_spec.rb
Stubbing with arguments - examples used in my "(More) Specific Stubbing with RSpec" blog post
class GivesCreditToPreferredCustomers
LOOK_BACK_PERIOD = 3
def self.for_large_orders(sales_amount, added_credit)
# the has_large_purchases scope now takes two arguments
preferred_customers = Customer.has_large_purchases(sales_amount, LOOK_BACK_PERIOD)
preferred_customers.each do |customer|
customer.add_credit added_credit
end
end
end
# Depends on working pdftk, gm (GraphicsMagick), and pdftotext (Poppler) commands.
# Splits a pdf into batches of N pages, creates their thumbnails and icons,
# as specified in the Job options, gets the text for every page, and merges
# it all back into a tar archive for convenient download.
#
# See <tt>examples/process_pdfs_example.rb</tt> for more information.
class ProcessPdfs < CloudCrowd::Action
# Split up a large pdf into single-page pdfs. Batch them into 'batch_size'
# chunks for processing. The double pdftk shuffle fixes the document xrefs.
def interpret_time(time)
return nil if time.blank?
return time if time.kind_of?(Time) or time.kind_of?(Date)
named_time(time) || time_by_regex(time) || Time.parse(time)
end
def named_time(time)
case time.downcase
when "today" : Date.today
when "now" : Time.now
describe Tweet do
describe "basic fetching of tweets" do
describe "(search conditions)" do
attr_reader :new_search
before do
@new_search = mock(Twitter::Search, :null_object => true)
Twitter::Search.should_receive(:new).and_return(new_search)
end
after do
Tweet.fetch_new_tweets