diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d48bf2643..abe733cdf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,29 +11,6 @@ require 'spork' require 'fakeweb' FakeWeb.allow_net_connect = false -module Helpers - - def self.next_seq - @next_seq = (@next_seq || 0) + 1 - end - - def log_in(fabricator=nil) - user = Fabricate(fabricator || :user) - log_in_user(user) - user - end - - def log_in_user(user) - session[:current_user_id] = user.id - end - - def fixture_file(filename) - return '' if filename == '' - file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename) - File.read(file_path) - end -end - Spork.prefork do # 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 @@ -53,15 +30,14 @@ Spork.prefork do # in spec/support/ and its subdirectories. Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} - # let's not run seed_fu every test SeedFu.quiet = true if SeedFu.respond_to? :quiet SeedFu.seed RSpec.configure do |config| - config.fail_fast = ENV['RSPEC_FAIL_FAST'] == "1" config.include Helpers + config.include MessageBus config.mock_framework = :mocha config.order = 'random' @@ -124,50 +100,6 @@ Spork.each_run do $redis.client.reconnect Rails.cache.reconnect MessageBus.after_fork - -end - -def build(*args) - Fabricate.build(*args) -end - -def create_topic(args={}) - args[:title] ||= "This is my title #{Helpers.next_seq}" - user = args.delete(:user) || Fabricate(:user) - guardian = Guardian.new(user) - TopicCreator.create(user, guardian, args) -end - -def create_post(args={}) - args[:title] ||= "This is my title #{Helpers.next_seq}" - args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}" - args[:topic_id] = args[:topic].id if args[:topic] - user = args.delete(:user) || Fabricate(:user) - PostCreator.create(user, args) -end - -module MessageBus::DiagnosticsHelper - def publish(channel, data, opts = nil) - id = super(channel, data, opts) - if @tracking - m = MessageBus::Message.new(-1, id, channel, data) - m.user_ids = opts[:user_ids] if opts - m.group_ids = opts[:group_ids] if opts - @tracking << m - end - id - end - - def track_publish - @tracking = tracking = [] - yield - @tracking = nil - tracking - end -end - -module MessageBus - extend MessageBus::DiagnosticsHelper end # --- Instructions --- @@ -198,5 +130,3 @@ end # # These instructions should self-destruct in 10 seconds. If they don't, feel # free to delete them. - - diff --git a/spec/support/diagnostics_helper.rb b/spec/support/diagnostics_helper.rb new file mode 100644 index 000000000..5d4c9eed4 --- /dev/null +++ b/spec/support/diagnostics_helper.rb @@ -0,0 +1,23 @@ +module MessageBus::DiagnosticsHelper + def publish(channel, data, opts = nil) + id = super(channel, data, opts) + if @tracking + m = MessageBus::Message.new(-1, id, channel, data) + m.user_ids = opts[:user_ids] if opts + m.group_ids = opts[:group_ids] if opts + @tracking << m + end + id + end + + def track_publish + @tracking = tracking = [] + yield + @tracking = nil + tracking + end +end + +module MessageBus + extend MessageBus::DiagnosticsHelper +end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb new file mode 100644 index 000000000..4e4c3f623 --- /dev/null +++ b/spec/support/helpers.rb @@ -0,0 +1,45 @@ +module Helpers + def self.next_seq + @next_seq = (@next_seq || 0) + 1 + end + + def log_in(fabricator=nil) + user = Fabricate(fabricator || :user) + log_in_user(user) + user + end + + def log_in_user(user) + session[:current_user_id] = user.id + end + + def fixture_file(filename) + return '' if filename.blank? + file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename) + File.read(file_path) + end + + def build(*args) + Fabricate.build(*args) + end + + def create_topic(args={}) + args[:title] ||= "This is my title #{Helpers.next_seq}" + user = args.delete(:user) || Fabricate(:user) + guardian = Guardian.new(user) + TopicCreator.create(user, guardian, args) + end + + def create_post(args={}) + args[:title] ||= "This is my title #{Helpers.next_seq}" + args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}" + args[:topic_id] = args[:topic].id if args[:topic] + user = args.delete(:user) || Fabricate(:user) + PostCreator.create(user, args) + end + + def generate_username(length=10) + range = [*'a'..'z'] + Array.new(length){range.sample}.join + end +end