File: rails.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (31 lines) | stat: -rw-r--r-- 845 bytes parent folder | download | duplicates (6)
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
27
28
29
30
31
module TestHelper
  module Rails
    def call
      super

      content = File.read(path)

      regexp = Regexp.new(
        '(' + start_of_requires.source + '.+?\n\n)',
        Regexp::MULTILINE
      )
      requires = project.requires_with_rr(@requires)
      require_lines = project.require_lines(requires).
        map { |str| "#{str}\n" }.
        join
      unless content.gsub!(regexp, '\1' + require_lines + "\n")
        raise "Regexp didn't match!\nRegex: #{regexp}\nContent:\n#{content}"
      end

      content << "\n\n" + @prelude

      File.open(path, 'w') { |f| f.write(content) }

      if RR.debug?
        puts "~ Content of #{File.basename(path)} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        puts File.read(path)
        puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
      end
    end
  end
end