Skip to content
Merged
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
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ RSpec/DescribeClass:
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/scripts/create_patch_spec.rb'
- 'spec/scripts/entry_points_spec.rb'
- 'spec/scripts/export_comments_spec.rb'
- 'spec/scripts/import_comments_spec.rb'
- 'spec/scripts/member_images_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion import-comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def run
end
end

exit ExportComments.new(ARGV).run if File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
exit ImportComments.new(ARGV).run if File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
35 changes: 35 additions & 0 deletions spec/scripts/entry_points_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require_relative "../spec_helper"

# A script that starts the wrong class does the wrong job when run, yet still
# passes a syntax check, so compare the two by reading the source.
RSpec.describe "entry scripts" do
# The line that runs the script when it is started directly
def self.entry_line(path)
File.readlines(path).find { |line| line.match?(/\$PROGRAM_NAME.*__FILE__/) }
end

def self.entry_scripts
Dir[File.expand_path("../../*.rb", __dir__)].select { |path| entry_line(path) }
end

# Classes the script defines itself or in the files it loads with require_relative
def classes_defined_for(path)
source = File.read(path)
loaded = source.scan(/^require_relative "(.+)"/).flatten.map { |name| File.expand_path("#{name}.rb", File.dirname(path)) }
([source] + loaded.select { |file| File.exist?(file) }.map { |file| File.read(file) })
.flat_map { |text| text.scan(/^class (\w+)/).flatten }
end

it "finds the entry scripts" do
expect(self.class.entry_scripts.size).to be > 5
end

entry_scripts.each do |path|
it "#{File.basename(path)} starts a class it defines or loads" do
started_class = self.class.entry_line(path)[/(\w+)\.new\b/, 1]
expect(classes_defined_for(path)).to include(started_class)
end
end
end
Loading