2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "tmpdir"
|
2015-12-07 01:16:18 -05:00
|
|
|
|
|
|
|
module PluginTestHelper
|
|
|
|
def create_test_file(name, pass: true)
|
|
|
|
plugin_file "test/#{name}_test.rb", <<-RUBY
|
2020-03-29 19:30:52 -04:00
|
|
|
require "test_helper"
|
2015-12-07 01:16:18 -05:00
|
|
|
|
|
|
|
class #{name.camelize}Test < ActiveSupport::TestCase
|
|
|
|
def test_truth
|
|
|
|
puts "#{name.camelize}Test"
|
|
|
|
assert #{pass}, 'wups!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
def plugin_file(path, contents, mode: "w")
|
2015-12-07 01:16:18 -05:00
|
|
|
FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}")
|
|
|
|
File.open("#{plugin_path}/#{path}", mode) do |f|
|
|
|
|
f.puts contents
|
|
|
|
end
|
|
|
|
end
|
2022-01-05 16:33:18 -05:00
|
|
|
|
|
|
|
def fill_in_gemspec_fields(gemspec_path = "#{plugin_path}/#{File.basename plugin_path}.gemspec")
|
|
|
|
# Some fields must be a valid URL.
|
|
|
|
filled_in = File.read(gemspec_path).gsub(/"TODO.*"/, "http://example.com".inspect)
|
|
|
|
File.write(gemspec_path, filled_in)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_rails_gem_to_repository(gemfile_path = "#{plugin_path}/Gemfile")
|
|
|
|
repository_path = File.expand_path("../../..", __dir__)
|
|
|
|
File.write(gemfile_path, "gem 'rails', path: #{repository_path.inspect}\n", mode: "a")
|
|
|
|
end
|
2015-12-07 01:16:18 -05:00
|
|
|
end
|