Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moving tests out into their own file, and a rakefile that'll run 'em …

…for ya
  • Loading branch information...
commit eb44f2771c7935ddd0c4513dcf75dd8eecc5b2d8 1 parent e378d42
Ryan Allen authored
Showing with 123 additions and 120 deletions.
  1. +0 −120 modelling.rb
  2. +116 −0 modelling_test.rb
  3. +7 −0 rakefile.rb
120 modelling.rb
View
@@ -78,123 +78,3 @@ def initialize(args = {})
end
end
-
-if __FILE__ == $0
-
- require 'test/unit'
-
- # this raises an error if the class vars are not initialized by
- # default, we do this here before the unit tests below so we can
- # test for this case before other classes start using their class
- # level macros :) complete hack, but it fulfils the test criteria
- class BlankSlate; include Modelling; end
- BlankSlate.new
-
- class User
- include Modelling
- attributes :name, :age
- collections :fav_colours, :biggest_gripes
- end
-
- class MyArray < Array; end
- class MyHash < Hash; end
-
- class Car
- include Modelling
- attributes :name => Proc.new { |car| String.new(car.class.to_s) }
- collections :doors => MyArray
- end
-
- class Site
- include Modelling
- maps :users => MyHash
- end
-
- class Bike
- include Modelling
- attributes :manufacturer
- maps :stickers
- end
-
- class ModellingTest < Test::Unit::TestCase
-
- def test_can_has_domain_builder
- assert Modelling
- end
-
- def test_user_has_name
- user = User.new
- user.name = 'Ryan'
- assert_equal 'Ryan', user.name
- end
-
- def test_user_has_age
- user = User.new
- user.age = 24
- assert_equal 24, user.age
- end
-
- def test_user_has_fav_colours_collection
- user = User.new
- user.fav_colours = [:green, :yellow]
- assert_equal [:green, :yellow], user.fav_colours
- end
-
- def test_user_has_biggest_gripes_collection
- user = User.new
- user.biggest_gripes = [:mediocrity, :CUB_beer]
- assert_equal [:mediocrity, :CUB_beer], user.biggest_gripes
- end
-
- def test_attributes_are_initialized_as_nil
- user = User.new
- assert_nil user.name
- assert_nil user.age
- end
-
- def test_collections_are_initialized_as_empty_array
- user = User.new
- assert_equal [], user.fav_colours
- assert_equal [], user.biggest_gripes
- end
-
- def test_can_initialize_with_attributes
- user = User.new(:name => 'Ryan')
- assert_equal 'Ryan', user.name
- end
-
- def test_can_initialize_with_collections
- user = User.new(:biggest_gripes => [:mediocrity, :CUB_beer])
- assert_equal [:mediocrity, :CUB_beer], user.biggest_gripes
- end
-
- def test_car_has_doors_and_all_is_good
- car = Car.new
- assert_equal [], car.doors
- end
-
- def test_bike_does_not_bunk_on_having_no_collection
- bike = Bike.new(:manufacturer => 'Kawasaki')
- # if nothing is rased, we fixed the bug
- end
-
- def test_bike_has_map_of_stickers
- assert_equal({}, Bike.new.stickers)
- end
-
- def test_cars_doors_is_a_my_array
- assert_kind_of MyArray, Car.new.doors
- end
-
- def test_sites_users_is_a_my_hash
- assert_kind_of MyHash, Site.new.users
- end
-
- def test_can_initialize_with_proc_and_get_reference_to_new_instance
- car = Car.new
- assert_equal String.new(car.class.to_s), car.name
- end
-
- end
-
-end
116 modelling_test.rb
View
@@ -0,0 +1,116 @@
+require 'test/unit'
+require 'modelling'
+
+# this raises an error if the class vars are not initialized by
+# default, we do this here before the unit tests below so we can
+# test for this case before other classes start using their class
+# level macros :) complete hack, but it fulfils the test criteria
+class BlankSlate; include Modelling; end
+BlankSlate.new
+
+class User
+ include Modelling
+ attributes :name, :age
+ collections :fav_colours, :biggest_gripes
+end
+
+class MyArray < Array; end
+class MyHash < Hash; end
+
+class Car
+ include Modelling
+ attributes :name => Proc.new { |car| String.new(car.class.to_s) }
+ collections :doors => MyArray
+end
+
+class Site
+ include Modelling
+ maps :users => MyHash
+end
+
+class Bike
+ include Modelling
+ attributes :manufacturer
+ maps :stickers
+end
+
+class ModellingTest < Test::Unit::TestCase
+
+ def test_can_has_domain_builder
+ assert Modelling
+ end
+
+ def test_user_has_name
+ user = User.new
+ user.name = 'Ryan'
+ assert_equal 'Ryan', user.name
+ end
+
+ def test_user_has_age
+ user = User.new
+ user.age = 24
+ assert_equal 24, user.age
+ end
+
+ def test_user_has_fav_colours_collection
+ user = User.new
+ user.fav_colours = [:green, :yellow]
+ assert_equal [:green, :yellow], user.fav_colours
+ end
+
+ def test_user_has_biggest_gripes_collection
+ user = User.new
+ user.biggest_gripes = [:mediocrity, :CUB_beer]
+ assert_equal [:mediocrity, :CUB_beer], user.biggest_gripes
+ end
+
+ def test_attributes_are_initialized_as_nil
+ user = User.new
+ assert_nil user.name
+ assert_nil user.age
+ end
+
+ def test_collections_are_initialized_as_empty_array
+ user = User.new
+ assert_equal [], user.fav_colours
+ assert_equal [], user.biggest_gripes
+ end
+
+ def test_can_initialize_with_attributes
+ user = User.new(:name => 'Ryan')
+ assert_equal 'Ryan', user.name
+ end
+
+ def test_can_initialize_with_collections
+ user = User.new(:biggest_gripes => [:mediocrity, :CUB_beer])
+ assert_equal [:mediocrity, :CUB_beer], user.biggest_gripes
+ end
+
+ def test_car_has_doors_and_all_is_good
+ car = Car.new
+ assert_equal [], car.doors
+ end
+
+ def test_bike_does_not_bunk_on_having_no_collection
+ bike = Bike.new(:manufacturer => 'Kawasaki')
+ # if nothing is rased, we fixed the bug
+ end
+
+ def test_bike_has_map_of_stickers
+ assert_equal({}, Bike.new.stickers)
+ end
+
+ def test_cars_doors_is_a_my_array
+ assert_kind_of MyArray, Car.new.doors
+ end
+
+ def test_sites_users_is_a_my_hash
+ assert_kind_of MyHash, Site.new.users
+ end
+
+ def test_can_initialize_with_proc_and_get_reference_to_new_instance
+ car = Car.new
+ assert_equal String.new(car.class.to_s), car.name
+ end
+
+end
7 rakefile.rb
View
@@ -0,0 +1,7 @@
+task :default do
+ Rake::Task['run_tests'].invoke
+end
+
+task :run_tests do
+ require 'modelling_test'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.