diff --git a/spec/nice_response.rb b/spec/nice_response.rb new file mode 100644 index 000000000..19ab3b2fa --- /dev/null +++ b/spec/nice_response.rb @@ -0,0 +1,48 @@ + +class NiceResponse + attr_reader :r, :body + + def initialize(r) + @r = r + @body = r.body.read + end + + def path + r.path + end + + def pretty_url + r.method + " " + r.path.first(45) + query + end + + def has_params? + r.params + .except(:controller, :action, :format, :id) + .keys + .length > 0 + end + + def has_body? + r.body.size > 4 + end + + def display_body + begin + JSON + .pretty_generate(JSON.parse(body)) + .first(500) + rescue + JSON.pretty_generate(r + .params + .except(:controller, :action, :format, :id, :user_id, :device_id)).first(500) + end + end + + def query + if r.query_string.present? + "?" + r.query_string.first(45) + else + "" + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4b14b56d7..57be6c75a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,23 +1,26 @@ ENV['MQTT_HOST'] = "blooper.io" ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com" +ENV['RAILS_ENV'] ||= 'test' require 'simplecov' +require 'codecov' +require 'pry' +require File.expand_path('../../config/environment', __FILE__) +require 'rspec/rails' +require 'database_cleaner' +require_relative './stuff' +require_relative './topic_stub' +require_relative './nice_response' #Ignore anything with the word 'spec' in it. No need to test your tests. SimpleCov.start do add_filter '/spec/' add_filter 'config/initializers' end -require 'codecov' SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::Codecov, ]) -require 'pry' -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rspec/rails' -require_relative './stuff' Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } @@ -26,7 +29,6 @@ SmarfDoc.config do |c| c.output_file = 'api_docs.md' end -require 'database_cleaner' DatabaseCleaner.strategy = :truncation # then, whenever you need to clean the DB DatabaseCleaner.clean @@ -64,76 +66,3 @@ def const_reassign(target, const, value) target.send(:remove_const, const) target.const_set(const, value) end - -class NiceResponse - attr_reader :r, :body - - def initialize(r) - @r = r - @body = r.body.read - end - - def path - r.path - end - - def pretty_url - r.method + " " + r.path.first(45) + query - end - - def has_params? - r.params - .except(:controller, :action, :format, :id) - .keys - .length > 0 - end - - def has_body? - r.body.size > 4 - end - - def display_body - begin - JSON - .pretty_generate(JSON.parse(body)) - .first(500) - rescue - JSON.pretty_generate(r - .params - .except(:controller, :action, :format, :id, :user_id, :device_id)).first(500) - end - end - - def query - if r.query_string.present? - "?" + r.query_string.first(45) - else - "" - end - end -end - -# BEGIN MQTT STUBS ======================================================= - -class TopicStub - def self.publish(msg, opts) - end -end - -class ChannelStub - def self.topic(name, opts) - return TopicStub - end -end - -class MQTTStub - def self.create_channel - return ChannelStub - end -end - -def Transport.connection - return MQTTStub -end - -# END MQTT STUBS ========================================================= diff --git a/spec/topic_stub.rb b/spec/topic_stub.rb new file mode 100644 index 000000000..3a3e5bb4a --- /dev/null +++ b/spec/topic_stub.rb @@ -0,0 +1,21 @@ +# Fake RabbitMQ adapter for when we test things. +class TopicStub + def self.publish(msg, opts) + end +end + +class ChannelStub + def self.topic(name, opts) + return TopicStub + end +end + +class MQTTStub + def self.create_channel + return ChannelStub + end +end + +def Transport.connection + return MQTTStub +end