finished move to merb-E-mart.
[merb_mart.git] / spec / spec_helper.rb
blobefafe43c4db672f9dc5a258e640f532062b4db9d
1 require 'rubygems'
2 require 'merb-core'
3 require 'spec'
4 require 'data_mapper'
5 require 'can_has_fixtures'
7 # Add the dependency in a before_app_loads hook
8 Merb::BootLoader.before_app_loads { require(File.join(File.dirname(__FILE__), '..', 'lib', 'merb-E-mart')) }
10 DataMapper.setup(:default, 'sqlite3::memory:')
11 DataMapper.auto_migrate!
13 # Using Merb.root below makes sure that the correct root is set for
14 # - testing standalone, without being installed as a gem and no host application
15 # - testing from within the host application; its root will be used
16 Merb.start_environment(
17   :testing => true, 
18   :adapter => 'runner', 
19   :environment => ENV['MERB_ENV'] || 'test',
20   :merb_root => Merb.root
23 module Merb
24   module Test
25     module SliceHelper
26       
27       # The absolute path to the current slice
28       def current_slice_root
29         @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
30       end
31       
32       # Whether the specs are being run from a host application or standalone
33       def standalone?
34         not $SLICED_APP
35       end
36       
37     end
38   end
39 end
41 Spec::Runner.configure do |config|
42   config.include(Merb::Test::ViewHelper)
43   config.include(Merb::Test::RouteHelper)
44   config.include(Merb::Test::ControllerHelper)
45   config.include(Merb::Test::SliceHelper)
46 end
48 Address.fixture {{
49   :first_name   => Random.word(:max => 50),
50   :last_name    => Random.word(:max => 50),
51   :address1     => Random.address,
52   :postal_code  => "%05d" % rand(100_000) + "-%04d" % rand([0, 1_000].random),
53   :company      => (1..4).random.of {Random.word(:max => 25)}.join(' '),
54   :telephone    => Random.phone_number,
55   :address2     => Random.address,
56   :city         => Random.word(:max => 50),
57   :country      => country = Country.gen,
58   :state        => State.gen(:country => country)
61 Country.fixture {{
62   :code => 2.of {('a'..'z').random}.to_s,
63   :name => Random.word(:max => 100, :unique => true)
66 State.fixture {{
67   :country  => Country.gen,
68   :name     => name = Random.word,
69   :abbr     => name[0, 10]
72 class Random
73   def address
74     "#{rand(100_000)} #{word(:max => 75)} #{%w[st rd ln ave pkwy].random}"
75   end
77   def phone_number
78     "#{(100..999).random}-#{(100..999).random}-#{(0..9999).random}"
79   end
80 end