diff options
author | Michael Herold <michael.j.herold@gmail.com> | 2017-02-10 19:33:02 -0600 |
---|---|---|
committer | Michael Herold <michael.j.herold@gmail.com> | 2017-02-10 19:36:20 -0600 |
commit | 7742133ffed9443dca581da597d44fb7dc0dd96d (patch) | |
tree | 2231a3869ec53ee582c0b7c00f02eef9eb814ee6 /spec | |
parent | 9636f682644cb34e69dcaa0c01693c7dc0ba0d1b (diff) | |
download | hashie-7742133ffed9443dca581da597d44fb7dc0dd96d.tar.gz |
Clean up integration specs to test for STDOUT log
This standardizes the way we're loading the example applications for the
integration tests so we're actually testing the behavior of the
application in each case. They're also structured in such a way to test
that the Hashie logger doesn't accidentally write to the STDOUT during
the initialization process of the applications.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/integration/omniauth-oauth2/Gemfile | 2 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/app.rb | 53 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/integration_spec.rb | 80 | ||||
-rw-r--r-- | spec/integration/omniauth/Gemfile | 2 | ||||
-rw-r--r-- | spec/integration/omniauth/app.rb | 11 | ||||
-rw-r--r-- | spec/integration/omniauth/integration_spec.rb | 33 | ||||
-rw-r--r-- | spec/integration/rails/Gemfile | 1 | ||||
-rw-r--r-- | spec/integration/rails/app.rb | 48 | ||||
-rw-r--r-- | spec/integration/rails/integration_spec.rb | 74 |
9 files changed, 164 insertions, 140 deletions
diff --git a/spec/integration/omniauth-oauth2/Gemfile b/spec/integration/omniauth-oauth2/Gemfile index c2f9159..5e2bdee 100644 --- a/spec/integration/omniauth-oauth2/Gemfile +++ b/spec/integration/omniauth-oauth2/Gemfile @@ -4,4 +4,4 @@ gem 'hashie', path: '../../..' gem 'omniauth-oauth2', '~> 1.4.0' gem 'rails', '~> 5.0.1' gem 'rspec', '~> 3.5.0' -gem 'rack-test', '~> 0.6.3' +gem 'rspec-rails' diff --git a/spec/integration/omniauth-oauth2/app.rb b/spec/integration/omniauth-oauth2/app.rb new file mode 100644 index 0000000..3784148 --- /dev/null +++ b/spec/integration/omniauth-oauth2/app.rb @@ -0,0 +1,53 @@ +require 'action_controller/railtie' +require 'action_view/railtie' +require 'action_view/testing/resolvers' +require 'rails/test_unit/railtie' +require_relative 'some_site' + +module RailsApp + class Application < ::Rails::Application + config.eager_load = false + config.secret_key_base = 'hashieintegrationtest' + + config.middleware.use OmniAuth::Builder do + provider :some_site + end + + routes.append do + get '/' => 'application#index' + end + end +end + +LAYOUT = <<-HTML +<!DOCTYPE html> +<html> +<head> + <title>TestApp</title> + <%= csrf_meta_tags %> +</head> +<body> +<%= yield %> +</body> +</html> +HTML + +INDEX = '<h1>Hello, world!</h1>' + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + + layout 'application' + + self.view_paths = [ActionView::FixtureResolver.new( + 'layouts/application.html.erb' => LAYOUT, + 'application/index.html.erb' => INDEX + )] + + def index + end +end + +Bundler.require(:default, Rails.env) + +RailsApp::Application.initialize! diff --git a/spec/integration/omniauth-oauth2/integration_spec.rb b/spec/integration/omniauth-oauth2/integration_spec.rb index 3f3df8f..a7c912e 100644 --- a/spec/integration/omniauth-oauth2/integration_spec.rb +++ b/spec/integration/omniauth-oauth2/integration_spec.rb @@ -1,74 +1,26 @@ -$LOAD_PATH.unshift File.dirname(__FILE__) - -ENV['RACK_ENV'] = 'test' +ENV['RAILS_ENV'] = 'test' require 'rspec/core' -require 'rails' -require 'rails/all' -require 'action_view/testing/resolvers' -require 'some_site' - -module RailsApp - class Application < ::Rails::Application - config.action_dispatch.show_exceptions = false - config.active_support.deprecation = :stderr - config.eager_load = false - config.root = __dir__ - config.secret_key_base = 'hashieintegrationtest' - routes.append do - get '/' => 'application#index' - end +RSpec.describe 'omniauth-oauth2 inside of rails', type: :request do + let(:stdout) { StringIO.new } - config.assets.paths << File.join(__dir__, 'assets/javascripts') - config.assets.debug = true + around(:each) do |example| + original_stdout = $stdout + $stdout = stdout + require_relative 'app' + require 'rspec/rails' + example.run + $stdout = original_stdout end -end - -LAYOUT = <<-HTML -<!DOCTYPE html> -<html> -<head> - <title>TestApp</title> - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> -</head> -<body> -<%= yield %> -</body> -</html> -HTML - -INDEX = <<-HTML -<h1>Hello, world!</h1> -HTML - -class ApplicationController < ActionController::Base - include Rails.application.routes.url_helpers - - layout 'application' - self.view_paths = [ActionView::FixtureResolver.new( - 'layouts/application.html.erb' => LAYOUT, - 'application/index.html.erb' => INDEX - )] - - def index + it 'does not log anything to STDOUT when initializing a Rails app and is set to Rails logger' do + expect(stdout.string).to eq('') + expect(Hashie.logger).to eq(Rails.logger) end -end -Rails.application.config.middleware.use OmniAuth::Builder do - provider :some_site -end - -# the order is important -# hashie must be loaded first to register the railtie -require 'hashie' -RailsApp::Application.initialize! - -RSpec.describe 'the Hashie logger' do - it 'is set to the Rails logger' do - expect(Hashie.logger).to eq(Rails.logger) + it 'works' do + get '/' + assert_select 'h1', 'Hello, world!' end end diff --git a/spec/integration/omniauth/Gemfile b/spec/integration/omniauth/Gemfile index 5e656f8..cbb4b87 100644 --- a/spec/integration/omniauth/Gemfile +++ b/spec/integration/omniauth/Gemfile @@ -1,7 +1,7 @@ source 'http://rubygems.org' gem 'hashie', path: '../../..' -gem 'omniauth', '~> 1.3.2' +gem 'omniauth', '~> 1.4.1' gem 'sinatra' gem 'rspec', '~> 3.5.0' gem 'rack-test', '~> 0.6.3' diff --git a/spec/integration/omniauth/app.rb b/spec/integration/omniauth/app.rb new file mode 100644 index 0000000..dc0a260 --- /dev/null +++ b/spec/integration/omniauth/app.rb @@ -0,0 +1,11 @@ +require 'sinatra' +require 'omniauth' + +class MyApplication < Sinatra::Base + use Rack::Session::Cookie, secret: 'hashie integration tests' + use OmniAuth::Strategies::Developer + + get '/' do + 'Hello World' + end +end diff --git a/spec/integration/omniauth/integration_spec.rb b/spec/integration/omniauth/integration_spec.rb index 848a61b..a1298dd 100644 --- a/spec/integration/omniauth/integration_spec.rb +++ b/spec/integration/omniauth/integration_spec.rb @@ -2,33 +2,34 @@ ENV['RACK_ENV'] = 'test' require 'rspec/core' require 'rack/test' -require 'sinatra' -require 'omniauth' -class MyApplication < Sinatra::Base - use Rack::Session::Cookie, secret: 'hashie integration tests' - use OmniAuth::Strategies::Developer - - get '/' do - 'Hello World' +RSpec.configure do |config| + config.expect_with :rspec do |expect| + expect.syntax = :expect end end -module RSpecMixin +RSpec.describe 'omniauth' do include Rack::Test::Methods + def app MyApplication end -end -RSpec.configure do |config| - config.include RSpecMixin - config.expect_with :rspec do |expect| - expect.syntax = :expect + let(:stdout) { StringIO.new } + + around(:each) do |example| + original_stdout = $stdout + $stdout = stdout + require_relative 'app' + example.run + $stdout = original_stdout + end + + it 'does not log anything to STDOUT when initializing' do + expect(stdout.string).to eq('') end -end -describe 'omniauth' do it 'works' do get '/' expect(last_response).to be_ok diff --git a/spec/integration/rails/Gemfile b/spec/integration/rails/Gemfile index 87bc758..32e1749 100644 --- a/spec/integration/rails/Gemfile +++ b/spec/integration/rails/Gemfile @@ -3,3 +3,4 @@ source 'http://rubygems.org' gem 'hashie', path: '../../..' gem 'rails', '~> 5.0.1' gem 'rspec', '~> 3.5.0' +gem 'rspec-rails' diff --git a/spec/integration/rails/app.rb b/spec/integration/rails/app.rb new file mode 100644 index 0000000..9eed330 --- /dev/null +++ b/spec/integration/rails/app.rb @@ -0,0 +1,48 @@ +require 'action_controller/railtie' +require 'action_view/railtie' +require 'action_view/testing/resolvers' +require 'rails/test_unit/railtie' + +module RailsApp + class Application < ::Rails::Application + config.eager_load = false + config.secret_key_base = 'hashieintegrationtest' + + routes.append do + get '/' => 'application#index' + end + end +end + +LAYOUT = <<-HTML +<!DOCTYPE html> +<html> +<head> + <title>TestApp</title> + <%= csrf_meta_tags %> +</head> +<body> +<%= yield %> +</body> +</html> +HTML + +INDEX = '<h1>Hello, world!</h1>' + +class ApplicationController < ActionController::Base + include Rails.application.routes.url_helpers + + layout 'application' + + self.view_paths = [ActionView::FixtureResolver.new( + 'layouts/application.html.erb' => LAYOUT, + 'application/index.html.erb' => INDEX + )] + + def index + end +end + +Bundler.require(:default, Rails.env) + +RailsApp::Application.initialize! diff --git a/spec/integration/rails/integration_spec.rb b/spec/integration/rails/integration_spec.rb index 6c00b86..9b150a2 100644 --- a/spec/integration/rails/integration_spec.rb +++ b/spec/integration/rails/integration_spec.rb @@ -1,68 +1,26 @@ -ENV['RACK_ENV'] = 'test' +ENV['RAILS_ENV'] = 'test' require 'rspec/core' -require 'rails' -require 'rails/all' -require 'action_view/testing/resolvers' -module RailsApp - class Application < ::Rails::Application - config.action_dispatch.show_exceptions = false - config.active_support.deprecation = :stderr - config.eager_load = false - config.root = __dir__ - config.secret_key_base = 'hashieintegrationtest' +RSpec.describe 'rails', type: :request do + let(:stdout) { StringIO.new } - routes.append do - get '/' => 'application#index' - end - - config.assets.paths << File.join(__dir__, 'assets/javascripts') - config.assets.debug = true + around(:each) do |example| + original_stdout = $stdout + $stdout = stdout + require_relative 'app' + require 'rspec/rails' + example.run + $stdout = original_stdout end -end - -LAYOUT = <<-HTML -<!DOCTYPE html> -<html> -<head> - <title>TestApp</title> - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> -</head> -<body> -<%= yield %> -</body> -</html> -HTML - -INDEX = <<-HTML -<h1>Hello, world!</h1> -HTML - -class ApplicationController < ActionController::Base - include Rails.application.routes.url_helpers - - layout 'application' - self.view_paths = [ActionView::FixtureResolver.new( - 'layouts/application.html.erb' => LAYOUT, - 'application/index.html.erb' => INDEX - )] - - def index + it 'does not log anything to STDOUT when initializing and sets the Hashie logger to the Rails logger' do + expect(stdout.string).to eq('') + expect(Hashie.logger).to eq(Rails.logger) end -end -# the order is important -# hashie must be loaded first to register the railtie -# then we can initialize -require 'hashie' -RailsApp::Application.initialize! - -RSpec.describe 'the Hashie logger' do - it 'is set to the Rails logger' do - expect(Hashie.logger).to eq(Rails.logger) + it 'works' do + get '/' + assert_select 'h1', 'Hello, world!' end end |