public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
markbates (author)
Fri May 09 11:19:55 -0700 2008
commit  8785a32ba01de7ae12396b2f19dd6a7a5bb233ef
tree    1e87ad71cddd9df845ab82ead73d74709198ccdd
parent  8d2566325a92112360766fe1b28576fc3023e8fd
mack / test / test_helper.rb
100644 107 lines (85 sloc) 2.121 kb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'rubygems'
require "test/unit"
require 'rake'
require 'fileutils'
ENV["_mack_env"] = "test"
ENV["_mack_root"] = File.join(File.dirname(__FILE__), "fake_application")
 
if $genosaurus_output_directory.nil?
  $genosaurus_output_directory = ENV["_mack_root"]
  puts "$genosaurus_output_directory: #{$genosaurus_output_directory}"
end
 
# load the mack framework:
require(File.join(File.dirname(__FILE__), "..", "lib", 'mack'))
 
# not quite sure why, but when you run rake you need to keep reloading the routes. this doesn't seem
# to be a problem when running script/server or when running an individual test.
require(File.join(File.dirname(__FILE__), "fake_application", "config", "routes.rb"))
 
 
# place common methods, assertions, and other type things in this file so
# other tests will have access to them.
 
module Mack
  module Utils
    module Crypt
      class ReverseWorker
        
        def encrypt(x)
          x.reverse
        end
        
        def decrypt(x)
          x.reverse
        end
        
      end
    end
  end
end
 
class Test::Unit::TestCase
  
  class MockCookieJar
    def all
      {}
    end
  end
  
  class MockSession
    def id
      1
    end
  end
  
  class MockRequest
    def env
      {}
    end
    def session
      MockSession.new
    end
  end
  
  class MockController
    def params(key)
      @params[key.to_sym]
    end
    def initialize(options = {})
      @params = {:format => "html"}.merge(options)
    end
    def cookies
      MockCookieJar.new
    end
    def request
      MockRequest.new
    end
  end
  
  def erb(template)
    Mack::ViewBinder.render(template, MockController.new)
  end
  
  def models_directory
    File.join(Mack::Configuration.app_directory, "models")
  end
  
  def migrations_directory
    File.join(database_directory, "migrations")
  end
  
  def database_directory
    File.join(Mack::Configuration.root, "db")
  end
  
  def test_directory
    File.join(Mack::Configuration.root, "test")
  end
  
  def model_generator_cleanup
    clean_test_directory
    clean_models_directory
    clean_migrations_directory
  end
  
end