Skip to content

Commit

Permalink
Merge pull request #249 from pat/frozen-string-literals
Browse files Browse the repository at this point in the history
Update for frozen-string-literal friendliness.
  • Loading branch information
gsamokovarov authored Oct 5, 2017
2 parents 56b9253 + cde7236 commit ec96734
Show file tree
Hide file tree
Showing 63 changed files with 133 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/web-console.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'web_console'
2 changes: 2 additions & 0 deletions lib/web_console.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/dependencies/autoload'
require 'active_support/logger'

Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/context.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# A context lets you get object names related to the current session binding.
class Context
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# The base class for every Web Console related error.
Error = Class.new(StandardError)
Expand Down
4 changes: 3 additions & 1 deletion lib/web_console/evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# Simple Ruby code evaluator.
#
Expand Down Expand Up @@ -25,7 +27,7 @@ def eval(input)
def format_exception(exc)
backtrace = cleaner.clean(Array(exc.backtrace) - caller)

format = "#{exc.class.name}: #{exc}\n"
format = "#{exc.class.name}: #{exc}\n".dup
format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join
format
end
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/exception_mapper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class ExceptionMapper
def initialize(exception)
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kernel
module_function

Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/middleware.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/string/strip'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails/railtie'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# Web Console tailored request object.
class Request < ActionDispatch::Request
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/response.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# A response object that writes content before the closing </body> tag, if
# possible.
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/session.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# A session lets you persist an +Evaluator+ instance in memory associated
# with multiple bindings.
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/tasks/extensions.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :ext do
rootdir = Pathname('extensions')

Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/tasks/templates.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :templates do
desc 'Run tests for templates'
task test: [ :daemonize, :npm, :rackup, :wait, :mocha, :kill, :exit ]
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# A facade that handles template rendering and composition.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/testing/erb_precompiler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'web_console/testing/helper'
require 'web_console/testing/fake_middleware'

Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/testing/fake_middleware.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'action_view'
require 'web_console'
require 'web_console/testing/helper'
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/testing/helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
module Testing
module Helper
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
VERSION = '3.5.1'
end
2 changes: 2 additions & 0 deletions lib/web_console/view.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class View < ActionView::Base
# Execute a block only on error pages.
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/whiny_request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
# Noisy wrapper around +Request+.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/web_console/whitelist.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'ipaddr'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ControllerHelperTestController < ApplicationController
def index
@instance_variable = "Helper Test"
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/exception_test_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ExceptionTestController < ApplicationController
def index
test = "Test"
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/helper_error_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class HelperErrorController < ApplicationController
def index
end
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/helper_test_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class HelperTestController < ApplicationController
def index
@helper_test = "Helper Test"
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/model_test_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ModelTestController < ApplicationController
def index
LocalModel.new.work
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/tests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TestsController < ApplicationController
def render_console_ontop_of_text
render text: '<h1 id="greeting">Hello World</h1>'
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
2 changes: 2 additions & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.expand_path('../boot', __FILE__)

require "active_model/railtie"
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Load the rails application.
require File.expand_path('../application', __FILE__)

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Configure sensitive parameters which will be filtered from the log file.
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/wrap_parameters.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# This file contains settings for ActionController::ParamsWrapper which
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.routes.draw do
root to: "exception_test#index"

Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/bad_custom_error_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class BadCustomErrorScenario
class Error < StandardError
Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/basic_nested_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class BasicNestedScenario
def call
Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/custom_error_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class CustomErrorScenario
Error = Class.new(StandardError)
Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/eval_nested_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class EvalNestedScenario
def call
Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/flat_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class FlatScenario
def call
Expand Down
2 changes: 2 additions & 0 deletions test/support/scenarios/reraised_scenario.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module WebConsole
class ReraisedScenario
def call
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

case RUBY_ENGINE
when 'ruby', 'rbx'
require 'simplecov'
Expand Down
2 changes: 2 additions & 0 deletions test/web_console/context_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions test/web_console/evaluator_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions test/web_console/exception_mapper_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
Expand Down
2 changes: 2 additions & 0 deletions test/web_console/extensions_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'
require 'web_console/extensions'

Expand Down
2 changes: 2 additions & 0 deletions test/web_console/helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
Expand Down
14 changes: 8 additions & 6 deletions test/web_console/integration_test.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
class IntegrationTest < ActiveSupport::TestCase
test 'Exception#bindings returns all the bindings of where the error originated' do
exc = FlatScenario.new.call

assert_equal 4, exc.bindings.first.eval('__LINE__')
assert_equal 6, exc.bindings.first.eval('__LINE__')
end

test 'Exception#bindings returns all the bindings for a custom error' do
exc = CustomErrorScenario.new.call

assert_equal 6, exc.bindings.first.eval('__LINE__')
assert_equal 8, exc.bindings.first.eval('__LINE__')
end

test 'Exception#bindings returns all the bindings for a bad custom error' do
exc = BadCustomErrorScenario.new.call

assert_equal 11, exc.bindings.first.eval('__LINE__')
assert_equal 13, exc.bindings.first.eval('__LINE__')
end

test 'Exception#bindings goes down the stack' do
exc = BasicNestedScenario.new.call

assert_equal 12, exc.bindings.first.eval('__LINE__')
assert_equal 14, exc.bindings.first.eval('__LINE__')
end

test 'Exception#bindings inside of an eval' do
exc = EvalNestedScenario.new.call

assert_equal 12, exc.bindings.first.eval('__LINE__')
assert_equal 14, exc.bindings.first.eval('__LINE__')
end

test "re-raising doesn't lose Exception#bindings information" do
exc = ReraisedScenario.new.call

assert_equal 4, exc.bindings.first.eval('__LINE__')
assert_equal 6, exc.bindings.first.eval('__LINE__')
end

test 'Exception#bindings is empty when exception is still not raised' do
Expand Down
2 changes: 2 additions & 0 deletions test/web_console/middleware_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

module WebConsole
Expand Down
Loading

0 comments on commit ec96734

Please sign in to comment.