Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Standard Ruby #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exe/magic
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ when "spec"
suite = "rspec"
run_magic_test(suite, option, file_path)
when "--help"
help_info = %q(
help_info = "
Usage: `bin/magic [option] [path/to/file]`

option = 'test' # will run MiniTest
Expand All @@ -24,15 +24,15 @@ when "--help"
Assign `file_path` to the path of the file you want to test

Each run will implicitly pass the `MAGIC_TEST=1` environment variable in order to run Magic Test and it's debugger
)
"

puts help_info
else
quick_tip = %q(
quick_tip = '
To run Magic Test: `bin/magic [option] [path/to/file.rb]`

Run `bin/magic --help` for more information
)
'

puts quick_tip
end
4 changes: 2 additions & 2 deletions lib/generators/magic_test/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def layout_templates
end

def show_install_message
message = %q(
message = "
We just inserted:
`<%= render 'magic_test/support' if Rails.env.test? %>`
before each closing `</head>` tag in your all of your templates in your `layouts` directory.
Expand All @@ -67,7 +67,7 @@ def show_install_message
will work as expected.
Run your first Magic Test by typing `MAGIC_TEST=1 rails test test/system/basics_test.rb` or generate an executable
with `bundle binstubs magic_test` and then run `bin/magic test test/system/basics_test.rb` into your terminal!
)
"

puts message
end
Expand Down
14 changes: 7 additions & 7 deletions lib/magic_test/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def assert_selected_exists

filepath, line = get_last_caller(caller)

contents = File.open(filepath).read.lines
contents = File.read(filepath).lines
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
indentation = chunks[1].first.match(/^(\s*)/)[0]
chunks.first << indentation + "assert(page.has_content?('#{selected_text.gsub("'", "\\\\'")}'))" + "\n"
Expand All @@ -24,7 +24,7 @@ def track_keystrokes
def flush
filepath, line = get_last_caller(caller)

contents = File.open(filepath).read.lines
contents = File.read(filepath).lines
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
indentation = chunks[1].first.match(/^(\s*)/)[0]
output = page.evaluate_script("JSON.parse(sessionStorage.getItem('testingOutput'))")
Expand Down Expand Up @@ -54,7 +54,7 @@ def ok
filepath, line = get_last_caller(caller)

puts "(writing that to `#{filepath}`.)"
contents = File.open(filepath).read.lines
contents = File.read(filepath).lines
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
indentation = chunks[1].first.match(/^(\s*)/)[0]
get_last.each do |last|
Expand Down Expand Up @@ -91,11 +91,11 @@ def magic_test

def magic_test_pry_hook
Pry.hooks.add_hook(:before_session, "magic_test") do |output, binding, pry|
Pry.hooks.delete_hook(:before_session, 'magic_test')
magic_test_file_index = pry.backtrace.index{|line| line.include?(__FILE__)}
Pry.hooks.delete_hook(:before_session, "magic_test")
magic_test_file_index = pry.backtrace.index { |line| line.include?(__FILE__) }
# walk up backtrace until finding the original caller
until pry.backtrace[magic_test_file_index + 1].include?(pry.last_file) do
pry.run_command('up')
until pry.backtrace[magic_test_file_index + 1].include?(pry.last_file)
pry.run_command("up")
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
Expand Down Expand Up @@ -53,7 +53,7 @@
config.log_level = :info

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down Expand Up @@ -83,9 +83,9 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

Expand Down
4 changes: 2 additions & 2 deletions test/dummy/config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember this fix or the one below it with PORT 3000 caused me some issues in another project I was working on, so we might need to double check or ignore these lines before merging the PR.

min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

Expand All @@ -15,7 +15,7 @@

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
get 'home/show'
get "home/show"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Defines the root path route ("/")
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: (ENV['MAGIC_TEST'] ? :chrome : :headless_chrome), screen_size: (ENV['MAGIC_TEST'] ? [800, 1400] : [1400, 1400])
driven_by :selenium, using: (ENV["MAGIC_TEST"] ? :chrome : :headless_chrome), screen_size: (ENV["MAGIC_TEST"] ? [800, 1400] : [1400, 1400])
end
2 changes: 1 addition & 1 deletion test/dummy/test/system/basics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class BasicsTest < ApplicationSystemTestCase
test "getting started" do
visit root_path

magic_test
end
end
2 changes: 1 addition & 1 deletion test/generators/magic_test/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_file(config_file, env_var)

# Ensure layouts container the render method for the partial
regex = /^\s*\<%= *render \'magic_test\/support\'.*\s*\<\/head>/
regex = /^\s*<%= *render 'magic_test\/support'.*\s*<\/head>/

assert_file_contains("application.html.erb", regex)
assert_file_contains("dashboard.html.erb", regex)
Expand Down