File: plugin_test_helper.rb

package info (click to toggle)
rails 2%3A6.1.7.10%2Bdfsg-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,756 kB
  • sloc: ruby: 290,662; javascript: 19,241; yacc: 46; sql: 43; makefile: 32; sh: 18
file content (26 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

require "abstract_unit"
require "tmpdir"

module PluginTestHelper
  def create_test_file(name, pass: true)
    plugin_file "test/#{name}_test.rb", <<-RUBY
      require "test_helper"

      class #{name.camelize}Test < ActiveSupport::TestCase
        def test_truth
          puts "#{name.camelize}Test"
          assert #{pass}, 'wups!'
        end
      end
    RUBY
  end

  def plugin_file(path, contents, mode: "w")
    FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}")
    File.open("#{plugin_path}/#{path}", mode) do |f|
      f.puts contents
    end
  end
end