File: helper.rb

package info (click to toggle)
ruby-premailer 1.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 440 kB
  • sloc: ruby: 2,344; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download
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
32
33
34
35
36
37
38
require 'maxitest/autorun'
require 'webmock/minitest'
require 'premailer'

class Premailer::TestCase < Minitest::Test
  BASE_URI  = 'http://premailer.dev/'
  BASE_PATH =  File.expand_path(File.dirname(__FILE__)) + '/files'

  def setup
    stub_request(:any, /premailer\.dev\/*/).to_return do |request|
      file_path = BASE_PATH + Addressable::URI.parse(request.uri).path
      if File.exist?(file_path)
        { :status => 200, :body => File.open(file_path) }
      else
        { :status => 404, :body => "#{file_path} not found" }
      end
    end

    stub_request(:get, /my\.example\.com\:8080\/*/).to_return(:status => 200, :body => "", :headers => {})
  end

  def default_test; end

  protected
  def local_setup(f = 'base.html', opts = {})
    base_file = BASE_PATH + '/' + f
    premailer = Premailer.new(base_file, opts)
    premailer.to_inline_css
    @doc = premailer.processed_doc
  end

  def remote_setup(f = 'base.html', opts = {})
    @premailer = Premailer.new(BASE_URI + "#{f}", opts)
    @premailer.to_inline_css
    @doc = @premailer.processed_doc
  end

end