spec/spec_helper.rb in openstax_exchange-0.0.0 vs spec/spec_helper.rb in openstax_exchange-0.0.1

- old
+ new

@@ -1,39 +1,53 @@ -ENV['RAILS_ENV'] ||= 'test' +require 'simplecov' +SimpleCov.start -require File.expand_path('../dummy/config/environment.rb', __FILE__) -require 'rspec/rails' +require 'vcr' -# Requires supporting ruby files with custom matchers and macros, etc, -Rails.backtrace_cleaner.remove_silencers! +VCR.configure do |c| + c.cassette_library_dir = 'spec/cassettes' + c.hook_into :webmock + c.configure_rspec_metadata! + # c.debug_logger = File.open("vcr_log.txt", "w") +end -# in spec/support/ and its subdirectories. -Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +accept_header = lambda do |request1, request2| + request1.headers['Accept'] == request2.headers['Accept'] +end -RSpec.configure do |config| - # ## Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr +authorization_header = lambda do |request1, request2| + request1.headers['Authorization'] == request2.headers['Authorization'] +end - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - # config.fixture_path = "#{::Rails.root}/spec/fixtures" +VCR_OPTS = { + record: :none, ## this should be :none before pushing + allow_unused_http_interactions: false, + match_requests_on: [:method, :uri, :host, :body, accept_header, authorization_header] +} - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.use_transactional_fixtures = true +require 'openstax_exchange' +require 'lib/openstax/exchange/shared_examples_for_exchange_client_v1' - # If true, the base class of anonymous controllers will be inferred - # automatically. This will be the default behavior in future versions of - # rspec-rails. - config.infer_base_class_for_anonymous_controllers = false +API_VERSION_V1 = 'v1' - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = "random" +DEFAULT_CLIENT_PLATFORM_ID = '123' +DEFAULT_CLIENT_PLATFORM_SECRET = 'abc' +DEFAULT_CLIENT_SERVER_SCHEME = 'http' +DEFAULT_CLIENT_SERVER_HOST = 'localhost' +DEFAULT_CLIENT_SERVER_PORT = 3003 +DEFAULT_CLIENT_SERVER_PATH = nil +DEFAULT_CLIENT_API_VERSION = API_VERSION_V1 + +def client_server_url(options = {}) + server_scheme = options.fetch(:scheme) { DEFAULT_CLIENT_SERVER_SCHEME } + server_host = options.fetch(:host) { DEFAULT_CLIENT_SERVER_HOST } + server_port = options.fetch(:port) { DEFAULT_CLIENT_SERVER_PORT } + server_path = options.fetch(:path) { DEFAULT_CLIENT_SERVER_PATH } + + url = URI::Generic.build( + scheme: server_scheme, + host: server_host, + port: server_port, + path: server_path) + + url.to_s end