carlosbrando-remarkable 0.0.99 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/History.txt +5 -5
  2. data/Manifest.txt +53 -35
  3. data/PostInstall.txt +1 -6
  4. data/README.rdoc +109 -15
  5. data/Rakefile +29 -29
  6. data/lib/remarkable/active_record/README.markdown +378 -0
  7. data/lib/remarkable/active_record/active_record.rb +12 -11
  8. data/lib/remarkable/active_record/helpers.rb +215 -5
  9. data/lib/remarkable/active_record/macros/associations/association_matcher.rb +242 -0
  10. data/lib/remarkable/active_record/macros/callbacks/callback_matcher.rb +46 -0
  11. data/lib/remarkable/active_record/macros/database/column_matcher.rb +122 -0
  12. data/lib/remarkable/active_record/macros/database/index_matcher.rb +103 -0
  13. data/lib/remarkable/active_record/macros/validations/allow_mass_assignment_of_matcher.rb +52 -0
  14. data/lib/remarkable/active_record/macros/validations/ensure_value_in_list_matcher.rb +83 -0
  15. data/lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb +172 -0
  16. data/lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb +54 -0
  17. data/lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb +54 -0
  18. data/lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb +94 -0
  19. data/lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb +48 -0
  20. data/lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb +51 -0
  21. data/lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb +79 -0
  22. data/lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb +177 -0
  23. data/lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb +74 -0
  24. data/lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb +38 -0
  25. data/lib/remarkable/active_record/macros/validations/validate_format_of_matcher.rb +33 -0
  26. data/lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb +45 -0
  27. data/lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb +248 -0
  28. data/lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb +206 -0
  29. data/lib/remarkable/active_record/macros/validations/validate_presence_of_matcher.rb +72 -0
  30. data/lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb +222 -0
  31. data/lib/remarkable/active_record/macros.rb +52 -0
  32. data/lib/remarkable/assertions.rb +29 -0
  33. data/lib/remarkable/controller/README.markdown +147 -0
  34. data/lib/remarkable/controller/controller.rb +11 -6
  35. data/lib/remarkable/controller/helpers.rb +4 -38
  36. data/lib/remarkable/controller/macros/assign_matcher.rb +85 -0
  37. data/lib/remarkable/controller/macros/filter_params_matcher.rb +63 -0
  38. data/lib/remarkable/controller/macros/metadata_matcher.rb +63 -0
  39. data/lib/remarkable/controller/macros/render_with_layout_matcher.rb +75 -0
  40. data/lib/remarkable/controller/macros/respond_with_content_type_matcher.rb +60 -0
  41. data/lib/remarkable/controller/macros/respond_with_matcher.rb +62 -0
  42. data/lib/remarkable/controller/macros/return_from_session_matcher.rb +58 -0
  43. data/lib/remarkable/controller/macros/route_matcher.rb +75 -0
  44. data/lib/remarkable/controller/macros/set_the_flash_to_matcher.rb +60 -0
  45. data/lib/remarkable/controller/macros.rb +78 -0
  46. data/lib/remarkable/dsl.rb +239 -0
  47. data/lib/remarkable/example/example_methods.rb +27 -7
  48. data/lib/remarkable/helpers.rb +28 -0
  49. data/lib/remarkable/matcher_base.rb +64 -0
  50. data/lib/remarkable/private_helpers.rb +10 -115
  51. data/lib/remarkable/rails.rb +27 -0
  52. data/lib/remarkable.rb +13 -5
  53. data/remarkable.gemspec +43 -0
  54. data/spec/controllers/posts_controller_spec.rb +58 -4
  55. data/spec/controllers/users_controller_spec.rb +1 -0
  56. data/spec/fixtures/fleas.yml +10 -0
  57. data/spec/fixtures/users.yml +7 -0
  58. data/spec/models/address_spec.rb +44 -0
  59. data/spec/models/dog_spec.rb +64 -3
  60. data/spec/models/flea_spec.rb +30 -0
  61. data/spec/models/post_spec.rb +36 -2
  62. data/spec/models/product_spec.rb +73 -8
  63. data/spec/models/tag_spec.rb +2 -2
  64. data/spec/models/tagging_spec.rb +24 -0
  65. data/spec/models/user_spec.rb +206 -21
  66. data/spec/other/custom_macros_spec.rb +27 -0
  67. data/spec/other/my_own_matcher_spec.rb +11 -0
  68. data/spec/other/private_helpers_spec.rb +31 -0
  69. data/spec/rails_root/app/controllers/posts_controller.rb +2 -0
  70. data/spec/rails_root/app/models/address.rb +2 -2
  71. data/spec/rails_root/app/models/flea.rb +4 -0
  72. data/spec/rails_root/app/models/pets/dog.rb +12 -0
  73. data/spec/rails_root/app/models/product.rb +7 -5
  74. data/spec/rails_root/app/models/tagging.rb +2 -0
  75. data/spec/rails_root/app/models/user.rb +20 -5
  76. data/spec/rails_root/app/views/layouts/posts.rhtml +8 -6
  77. data/spec/rails_root/config/database.yml +1 -2
  78. data/spec/rails_root/config/environment.rb +3 -1
  79. data/spec/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
  80. data/spec/rails_root/config/locales/en.yml +8 -0
  81. data/spec/rails_root/db/migrate/001_create_users.rb +2 -2
  82. data/spec/rails_root/db/migrate/005_create_dogs.rb +1 -0
  83. data/spec/rails_root/db/migrate/011_add_fleas_color.rb +10 -0
  84. data/spec/rails_root/db/migrate/012_add_fleas_address.rb +10 -0
  85. data/spec/rails_root/spec/remarkable_macros/.keep +0 -0
  86. data/spec/rails_root/vendor/plugins/my_plugin/remarkable_macros/.keep +0 -0
  87. data/spec/spec_helper.rb +0 -2
  88. metadata +63 -43
  89. data/lib/remarkable/active_record/macros/associations/belong_to.rb +0 -81
  90. data/lib/remarkable/active_record/macros/associations/have_and_belong_to_many.rb +0 -77
  91. data/lib/remarkable/active_record/macros/associations/have_many.rb +0 -160
  92. data/lib/remarkable/active_record/macros/associations/have_one.rb +0 -133
  93. data/lib/remarkable/active_record/macros/database/have_db_column.rb +0 -81
  94. data/lib/remarkable/active_record/macros/database/have_db_columns.rb +0 -73
  95. data/lib/remarkable/active_record/macros/database/have_indices.rb +0 -75
  96. data/lib/remarkable/active_record/macros/validations/allow_values_for.rb +0 -103
  97. data/lib/remarkable/active_record/macros/validations/ensure_length_at_least.rb +0 -97
  98. data/lib/remarkable/active_record/macros/validations/ensure_length_in_range.rb +0 -134
  99. data/lib/remarkable/active_record/macros/validations/ensure_length_is.rb +0 -106
  100. data/lib/remarkable/active_record/macros/validations/ensure_value_in_range.rb +0 -117
  101. data/lib/remarkable/active_record/macros/validations/have_class_methods.rb +0 -74
  102. data/lib/remarkable/active_record/macros/validations/have_instance_methods.rb +0 -74
  103. data/lib/remarkable/active_record/macros/validations/have_named_scope.rb +0 -148
  104. data/lib/remarkable/active_record/macros/validations/have_readonly_attributes.rb +0 -81
  105. data/lib/remarkable/active_record/macros/validations/only_allow_numeric_values_for.rb +0 -89
  106. data/lib/remarkable/active_record/macros/validations/protect_attributes.rb +0 -89
  107. data/lib/remarkable/active_record/macros/validations/require_acceptance_of.rb +0 -94
  108. data/lib/remarkable/active_record/macros/validations/require_attributes.rb +0 -94
  109. data/lib/remarkable/active_record/macros/validations/require_unique_attributes.rb +0 -146
  110. data/lib/remarkable/controller/macros/assign_to.rb +0 -110
  111. data/lib/remarkable/controller/macros/filter_params.rb +0 -52
  112. data/lib/remarkable/controller/macros/redirect_to.rb +0 -24
  113. data/lib/remarkable/controller/macros/render_a_form.rb +0 -23
  114. data/lib/remarkable/controller/macros/render_template.rb +0 -18
  115. data/lib/remarkable/controller/macros/render_with_layout.rb +0 -61
  116. data/lib/remarkable/controller/macros/respond_with.rb +0 -86
  117. data/lib/remarkable/controller/macros/respond_with_content_type.rb +0 -45
  118. data/lib/remarkable/controller/macros/return_from_session.rb +0 -45
  119. data/lib/remarkable/controller/macros/route.rb +0 -91
  120. data/lib/remarkable/controller/macros/set_the_flash_to.rb +0 -58
  121. data/spec/rails_root/app/models/dog.rb +0 -5
@@ -1,123 +1,18 @@
1
1
  module Remarkable # :nodoc:
2
- module Private # :nodoc:
3
- def fail(message)
4
- @failure_message = message
5
- raise Exception.new(message)
6
- end
7
-
8
- # Returns the values for the entries in the args hash who's keys are listed in the wanted array.
9
- # Will raise if there are keys in the args hash that aren't listed.
10
- def get_options!(args, *wanted)
11
- ret = []
12
- opts = (args.last.is_a?(Hash) ? args.pop : {})
13
- wanted.each {|w| ret << opts.delete(w)}
14
- raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
15
- return *ret
16
- end
17
-
18
- # Helper method that determines the default error message used by Active
19
- # Record. Works for both existing Rails 2.1 and Rails 2.2 with the newly
20
- # introduced I18n module used for localization.
21
- #
22
- # default_error_message(:blank)
23
- # default_error_message(:too_short, :count => 5)
24
- # default_error_message(:too_long, :count => 60)
25
- def default_error_message(key, values = {})
26
- if Object.const_defined?(:I18n) # Rails >= 2.2
27
- I18n.translate("activerecord.errors.messages.#{key}", values)
28
- else # Rails <= 2.1.x
29
- ::ActiveRecord::Errors.default_error_messages[key] % values[:count]
30
- end
31
- end
32
-
33
- # Asserts that an Active Record model validates with the passed
34
- # <tt>value</tt> by making sure the <tt>error_message_to_avoid</tt> is not
35
- # contained within the list of errors for that attribute.
36
- #
37
- # assert_good_value(User.new, :email, "user@example.com")
38
- # assert_good_value(User.new, :ssn, "123456789", /length/)
39
- #
40
- # If a class is passed as the first argument, a new object will be
41
- # instantiated before the assertion. If an instance variable exists with
42
- # the same name as the class (underscored), that object will be used
43
- # instead.
44
- #
45
- # assert_good_value(User, :email, "user@example.com")
46
- #
47
- # @product = Product.new(:tangible => false)
48
- # assert_good_value(Product, :price, "0")
49
- def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = //)
50
- object = get_instance_of(object_or_klass)
51
- object.send("#{attribute}=", value)
52
- return true if object.valid?
53
- assert_does_not_contain(object.errors.on(attribute), error_message_to_avoid)
54
- end
55
-
56
- # Asserts that an Active Record model invalidates the passed
57
- # <tt>value</tt> by making sure the <tt>error_message_to_expect</tt> is
58
- # contained within the list of errors for that attribute.
59
- #
60
- # assert_bad_value(User.new, :email, "invalid")
61
- # assert_bad_value(User.new, :ssn, "123", /length/)
62
- #
63
- # If a class is passed as the first argument, a new object will be
64
- # instantiated before the assertion. If an instance variable exists with
65
- # the same name as the class (underscored), that object will be used
66
- # instead.
67
- #
68
- # assert_bad_value(User, :email, "invalid")
69
- #
70
- # @product = Product.new(:tangible => true)
71
- # assert_bad_value(Product, :price, "0")
72
- def assert_bad_value(object_or_klass, attribute, value,
73
- error_message_to_expect = self.class.default_error_message(:invalid))
74
- object = get_instance_of(object_or_klass)
75
- object.send("#{attribute}=", value)
76
-
77
- return false if object.valid?
78
- return false unless object.errors.on(attribute)
79
- assert_contains(object.errors.on(attribute), error_message_to_expect)
80
- end
81
-
82
- # Asserts that the given collection contains item x. If x is a regular expression, ensure that
83
- # at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails.
84
- #
85
- # assert_contains(['a', '1'], /\d/) => passes
86
- # assert_contains(['a', '1'], 'a') => passes
87
- # assert_contains(['a', '1'], /not there/) => fails
88
- def assert_contains(collection, x)
89
- collection = [collection] unless collection.is_a?(Array)
90
- case x
91
- when Regexp
92
- return false unless collection.detect { |e| e =~ x }
2
+ module Private # :nodoc:
3
+ # Returns the model class constant, as determined by the test class name.
4
+ def subject_class
5
+ # TODO: fazer um mixin na classe de string para retornar o formato do variable_name
6
+ variable_name = "@#{instance_variable_name}"
7
+ if instance_variable_defined?(variable_name)
8
+ instance_variable_get(variable_name)
93
9
  else
94
- return false unless collection.include?(x)
10
+ self.class.described_type
95
11
  end
96
- true
97
12
  end
98
13
 
99
- # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
100
- # none of the elements from the collection match x.
101
- def assert_does_not_contain(collection, x)
102
- collection = [collection] unless collection.is_a?(Array)
103
- case x
104
- when Regexp
105
- return false if collection.detect { |e| e =~ x }
106
- else
107
- return false if collection.include?(x)
108
- end
109
- true
110
- end
111
-
112
- private
113
-
114
- def get_instance_of(object_or_klass)
115
- if object_or_klass.is_a?(Class)
116
- klass = object_or_klass
117
- instance_variable_get("@#{klass.to_s.underscore}") || klass.new
118
- else
119
- object_or_klass
120
- end
14
+ def instance_variable_name
15
+ self.class.described_type.to_s.split(':').last.underscore
121
16
  end
122
17
  end
123
18
  end
@@ -0,0 +1,27 @@
1
+ if defined?(RAILS_ROOT)
2
+
3
+ def create_macro_methods(macro)
4
+ method_name = File.basename(macro, ".rb")
5
+ Spec::Example::ExampleGroupMethods::send(:define_method, "should_#{method_name}") { instance_eval(IO.read(macro)) }
6
+
7
+ Spec::Rails::Matchers::send(:define_method, method_name) do
8
+ return simple_matcher(method_name.humanize.downcase) do
9
+ self.class.describe do
10
+ describe "(#{method_name})" do
11
+ instance_eval(IO.read(macro))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # load in the 3rd party macros from vendorized plugins and gems
19
+ Dir[File.join(RAILS_ROOT, "vendor", "{plugins, gems}", "*", "remarkable_macros", "*.rb")].each do |macro|
20
+ create_macro_methods(macro)
21
+ end
22
+
23
+ # load in the local application specific macros
24
+ Dir[File.join(RAILS_ROOT, "spec", "remarkable_macros", "*.rb")].each do |macro|
25
+ create_macro_methods(macro)
26
+ end
27
+ end
data/lib/remarkable.rb CHANGED
@@ -2,12 +2,20 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Remarkable
5
- VERSION = '0.0.99'
5
+ VERSION = '2.2.1'
6
6
  end
7
7
 
8
- require "spec"
8
+ if ENV['RAILS_ENV'] == 'test'
9
+ require 'spec/rails'
10
+ end
9
11
 
10
- require 'remarkable/example/example_methods'
12
+ require 'remarkable/dsl'
13
+ require 'remarkable/matcher_base'
11
14
  require 'remarkable/private_helpers'
12
- require 'remarkable/active_record/active_record'
13
- require 'remarkable/controller/controller'
15
+ require 'remarkable/helpers'
16
+ require 'remarkable/assertions'
17
+ require 'remarkable/example/example_methods'
18
+
19
+ require 'remarkable/active_record/active_record' if defined?(ActiveRecord::Base)
20
+ require 'remarkable/controller/controller' if defined?(ActionController::Base)
21
+ require 'remarkable/rails' if defined?(RAILS_ROOT)
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{remarkable}
5
+ s.version = "2.2.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Carlos Brando", "Diego Carrion", "José Valim"]
9
+ s.date = %q{2009-02-10}
10
+ s.description = %q{Remarkable is a framework for Rspec matchers.}
11
+ s.email = ["eduardobrando@gmail.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "init.rb", "lib/remarkable.rb", "lib/remarkable/active_record/README.markdown", "lib/remarkable/active_record/active_record.rb", "lib/remarkable/active_record/helpers.rb", "lib/remarkable/active_record/macros.rb", "lib/remarkable/active_record/macros/associations/association_matcher.rb", "lib/remarkable/active_record/macros/callbacks/callback_matcher.rb", "lib/remarkable/active_record/macros/database/column_matcher.rb", "lib/remarkable/active_record/macros/database/index_matcher.rb", "lib/remarkable/active_record/macros/validations/allow_mass_assignment_of_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_list_matcher.rb", "lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb", "lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb", "lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb", "lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb", "lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_format_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_presence_of_matcher.rb", "lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb", "lib/remarkable/assertions.rb", "lib/remarkable/controller/README.markdown", "lib/remarkable/controller/controller.rb", "lib/remarkable/controller/helpers.rb", "lib/remarkable/controller/macros.rb", "lib/remarkable/controller/macros/assign_matcher.rb", "lib/remarkable/controller/macros/filter_params_matcher.rb", "lib/remarkable/controller/macros/metadata_matcher.rb", "lib/remarkable/controller/macros/render_with_layout_matcher.rb", "lib/remarkable/controller/macros/respond_with_content_type_matcher.rb", "lib/remarkable/controller/macros/respond_with_matcher.rb", "lib/remarkable/controller/macros/return_from_session_matcher.rb", "lib/remarkable/controller/macros/route_matcher.rb", "lib/remarkable/controller/macros/set_the_flash_to_matcher.rb", "lib/remarkable/dsl.rb", "lib/remarkable/example/example_methods.rb", "lib/remarkable/helpers.rb", "lib/remarkable/matcher_base.rb", "lib/remarkable/private_helpers.rb", "lib/remarkable/rails.rb", "rails/init.rb", "remarkable.gemspec", "script/console", "script/destroy", "script/generate", "spec/controllers/posts_controller_spec.rb", "spec/controllers/users_controller_spec.rb", "spec/fixtures/addresses.yml", "spec/fixtures/fleas.yml", "spec/fixtures/friendships.yml", "spec/fixtures/posts.yml", "spec/fixtures/products.yml", "spec/fixtures/taggings.yml", "spec/fixtures/tags.yml", "spec/fixtures/users.yml", "spec/models/address_spec.rb", "spec/models/dog_spec.rb", "spec/models/flea_spec.rb", "spec/models/friendship_spec.rb", "spec/models/post_spec.rb", "spec/models/product_spec.rb", "spec/models/tag_spec.rb", "spec/models/tagging_spec.rb", "spec/models/user_spec.rb", "spec/other/custom_macros_spec.rb", "spec/other/my_own_matcher_spec.rb", "spec/other/private_helpers_spec.rb", "spec/rails_root/app/controllers/application.rb", "spec/rails_root/app/controllers/posts_controller.rb", "spec/rails_root/app/controllers/users_controller.rb", "spec/rails_root/app/helpers/application_helper.rb", "spec/rails_root/app/helpers/posts_helper.rb", "spec/rails_root/app/helpers/users_helper.rb", "spec/rails_root/app/models/address.rb", "spec/rails_root/app/models/flea.rb", "spec/rails_root/app/models/friendship.rb", "spec/rails_root/app/models/pets/dog.rb", "spec/rails_root/app/models/post.rb", "spec/rails_root/app/models/product.rb", "spec/rails_root/app/models/tag.rb", "spec/rails_root/app/models/tagging.rb", "spec/rails_root/app/models/user.rb", "spec/rails_root/app/views/layouts/posts.rhtml", "spec/rails_root/app/views/layouts/users.rhtml", "spec/rails_root/app/views/layouts/wide.html.erb", "spec/rails_root/app/views/posts/edit.rhtml", "spec/rails_root/app/views/posts/index.rhtml", "spec/rails_root/app/views/posts/new.rhtml", "spec/rails_root/app/views/posts/show.rhtml", "spec/rails_root/app/views/users/edit.rhtml", "spec/rails_root/app/views/users/index.rhtml", "spec/rails_root/app/views/users/new.rhtml", "spec/rails_root/app/views/users/show.rhtml", "spec/rails_root/config/boot.rb", "spec/rails_root/config/database.yml", "spec/rails_root/config/environment.rb", "spec/rails_root/config/environments/test.rb", "spec/rails_root/config/initializers/new_rails_defaults.rb", "spec/rails_root/config/initializers/shoulda.rb", "spec/rails_root/config/locales/en.yml", "spec/rails_root/config/routes.rb", "spec/rails_root/db/migrate/001_create_users.rb", "spec/rails_root/db/migrate/002_create_posts.rb", "spec/rails_root/db/migrate/003_create_taggings.rb", "spec/rails_root/db/migrate/004_create_tags.rb", "spec/rails_root/db/migrate/005_create_dogs.rb", "spec/rails_root/db/migrate/006_create_addresses.rb", "spec/rails_root/db/migrate/007_create_fleas.rb", "spec/rails_root/db/migrate/008_create_dogs_fleas.rb", "spec/rails_root/db/migrate/009_create_products.rb", "spec/rails_root/db/migrate/010_create_friendships.rb", "spec/rails_root/db/migrate/011_add_fleas_color.rb", "spec/rails_root/db/migrate/012_add_fleas_address.rb", "spec/rails_root/db/schema.rb", "spec/rails_root/log/.keep", "spec/rails_root/log/test.log", "spec/rails_root/public/.htaccess", "spec/rails_root/public/404.html", "spec/rails_root/public/422.html", "spec/rails_root/public/500.html", "spec/rails_root/script/console", "spec/rails_root/script/generate", "spec/rails_root/spec/remarkable_macros/.keep", "spec/rails_root/vendor/plugins/.keep", "spec/rails_root/vendor/plugins/my_plugin/remarkable_macros/.keep", "spec/rcov.opts", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
14
+ s.has_rdoc = true
15
+ s.post_install_message = %q{PostInstall.txt}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{remarkable}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Remarkable is a framework for Rspec matchers.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<rspec>, [">= 1.1.12"])
28
+ s.add_runtime_dependency(%q<rspec-rails>, [">= 1.1.12"])
29
+ s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
30
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
31
+ else
32
+ s.add_dependency(%q<rspec>, [">= 1.1.12"])
33
+ s.add_dependency(%q<rspec-rails>, [">= 1.1.12"])
34
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
35
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<rspec>, [">= 1.1.12"])
39
+ s.add_dependency(%q<rspec-rails>, [">= 1.1.12"])
40
+ s.add_dependency(%q<newgem>, [">= 1.2.3"])
41
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
42
+ end
43
+ end
@@ -3,8 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe PostsController do
4
4
  fixtures :all
5
5
 
6
+ integrate_views
7
+
6
8
  # autodetects the :controller
7
- should_route :get, '/posts', :controller => :posts, :action => :index
9
+ should_route :get, '/posts', :controller => :posts, :action => :index
10
+ should_not_route :get, '/posts', :controller => :posts, :action => :show
8
11
  # explicitly specify :controller
9
12
  should_route :post, '/posts', :controller => :posts, :action => :create
10
13
  # non-string parameter
@@ -33,10 +36,21 @@ describe PostsController do
33
36
  end
34
37
  should_respond_with 200
35
38
  should_assign_to :user, :class => User, :equals => 'users(:first)'
39
+ should_not_assign_to :user, :class => User, :equals => 'users(:second)'
40
+
41
+ should_not_assign_to :user, :class => Post
42
+ should_not_assign_to :user, :equals => 'posts(:first)'
36
43
  it { lambda { should_assign_to(:user, :class => Post) }.should raise_error }
37
- it { lambda { should_assign_to :user, :equals => 'posts(:first)' }.should raise_error }
44
+ it { lambda { should_assign_to(:user, :equals => 'posts(:first)') }.should raise_error }
45
+
38
46
  should_assign_to :posts
39
47
  should_not_assign_to :foo, :bar
48
+
49
+ # should_render_page_with_metadata :title => /index/
50
+ # should_render_page_with_metadata :description => /Posts/, :title => /index/
51
+ # should_render_page_with_metadata :keywords => "posts"
52
+ # should_not_render_page_with_metadata :description => "user"
53
+ # should_not_render_page_with_metadata :foo => "bar"
40
54
  end
41
55
 
42
56
  describe "on POST to :create" do
@@ -45,7 +59,11 @@ describe PostsController do
45
59
  @post = Post.last
46
60
  end
47
61
  should_respond_with :redirect
62
+ should_respond_with 302
63
+ should_not_respond_with :success
64
+
48
65
  should_redirect_to "user_post_url(@post.user, @post)"
66
+ should_not_redirect_to "user_url(@post.user)"
49
67
  should_set_the_flash_to /created/i
50
68
  end
51
69
 
@@ -58,17 +76,28 @@ describe PostsController do
58
76
  should_respond_with_content_type 'application/rss+xml'
59
77
  should_respond_with_content_type :rss
60
78
  should_respond_with_content_type /rss/
79
+
61
80
  should_return_from_session :special, "'$2 off your next purchase'"
62
81
  should_return_from_session :special_user_id, '@user.id'
82
+ should_not_return_from_session(:monkey, "'fat'")
83
+
63
84
  should_assign_to :user, :posts
64
85
  should_not_assign_to :foo, :bar
65
86
  end
66
87
 
67
88
  describe "viewing a post on GET to #show" do
68
89
  before { get :show, :user_id => users(:first), :id => posts(:first) }
90
+
69
91
  should_render_with_layout 'wide'
70
92
  should_render_with_layout :wide
93
+ should_not_render_with_layout 'other'
94
+
95
+ should_assign_to :false_flag
96
+
97
+ should_not_respond_with_content_type :rss
98
+
71
99
  should_render_template :show
100
+ should_not_render_template :new
72
101
  end
73
102
 
74
103
  describe "on GET to #new" do
@@ -83,8 +112,11 @@ end
83
112
  describe PostsController do
84
113
  fixtures :all
85
114
 
115
+ integrate_views
116
+
86
117
  # autodetects the :controller
87
- it { should route(:get, '/posts', :action => :index) }
118
+ it { should route(:get, '/posts', :action => :index) }
119
+ it { should_not route(:get, '/posts', :action => :show) }
88
120
  # explicitly specify :controller
89
121
  it { should route(:post, '/posts', :controller => :posts, :action => :create) }
90
122
  # # non-string parameter
@@ -112,21 +144,37 @@ describe PostsController do
112
144
  get :index, :user_id => users(:first)
113
145
  end
114
146
  it { should respond_with(200) }
147
+
148
+ it { should assign_to(:some_text) }
149
+ it { should assign_to(:some_text, :equals => "foo bar") }
150
+ it { should_not assign_to(:some_text, :equals => "foo without bar") }
115
151
  it { should assign_to(:user, :class => User, :equals => 'users(:first)') }
152
+ it { should assign_to(:user, :class => User, :equals => users(:first)) }
153
+ it { should_not assign_to(:user, :class => User, :equals => 'users(:second)') }
154
+ it { should_not assign_to(:user, :class => User, :equals => users(:second)) }
116
155
  it { should_not assign_to(:user, :class => Post) }
117
156
  it { should_not assign_to(:user, :equals => 'posts(:first)') }
118
157
  it { should assign_to(:posts) }
119
158
  it { should_not assign_to(:foo, :bar) }
159
+
160
+ # it { should render_page_with_metadata(:title => /index/) }
161
+ # it { should render_page_with_metadata(:description => /Posts/, :title => /index/) }
162
+ # it { should render_page_with_metadata(:keywords => "posts") }
163
+ # it { should_not render_page_with_metadata(:description => "user") }
164
+ # it { should_not render_page_with_metadata(:foo => "bar") }
120
165
  end
121
-
166
+
122
167
  describe "on POST to :create" do
123
168
  before(:each) do
124
169
  post :create, :post => { :title => "Title", :body => "Body" }, :user_id => users(:first)
125
170
  @post = Post.last
126
171
  end
127
172
  it { should respond_with(:redirect) }
173
+ it { should respond_with(302) }
128
174
  it { should_not respond_with(:success) }
175
+
129
176
  it { should redirect_to(user_post_url(@post.user, @post)) }
177
+ it { should_not redirect_to(user_url(@post.user)) }
130
178
  it { should set_the_flash_to(/created/i) }
131
179
  it { should_not set_the_flash_to(/foo/i) }
132
180
  end
@@ -149,9 +197,15 @@ describe PostsController do
149
197
 
150
198
  describe "viewing a post on GET to #show" do
151
199
  before { get :show, :user_id => users(:first), :id => posts(:first) }
200
+
152
201
  it { should render_with_layout('wide') }
153
202
  it { should render_with_layout(:wide) }
203
+ it { should_not render_with_layout('other') }
204
+
205
+ it { should assign_to(:false_flag) }
206
+
154
207
  it { should_not respond_with_content_type(:rss) }
208
+
155
209
  it { should render_template(:show) }
156
210
  it { should_not render_template(:new) }
157
211
  end
@@ -4,6 +4,7 @@ describe UsersController do
4
4
  fixtures :all
5
5
 
6
6
  should_filter_params :ssn
7
+ should_not_filter_params :email
7
8
  end
8
9
 
9
10
  describe UsersController do
@@ -0,0 +1,10 @@
1
+ first:
2
+ id: 1
3
+ name: rocky
4
+ address: ''
5
+
6
+ second:
7
+ id: 2
8
+ name: cool
9
+ color: blue
10
+ address: 'Here'
@@ -4,3 +4,10 @@ first:
4
4
  age: 2
5
5
  email: none@none.com
6
6
  ssn: 123456789
7
+
8
+ second:
9
+ id: 2
10
+ name: Another guy
11
+ age: 10
12
+ email: gut@none.com
13
+ ssn: 123456789
@@ -6,8 +6,32 @@ describe Address do
6
6
  it { should belong_to(:addressable) }
7
7
 
8
8
  it { should require_unique_attributes(:title, :scoped_to => [:addressable_id, :addressable_type]) }
9
+ it { should require_unique_attributes(:title).scoped_to([:addressable_id, :addressable_type]) }
10
+ it { should_not require_unique_attributes(:title, :scoped_to => [:addressable_id]) }
11
+ it { should_not require_unique_attributes(:zip) }
12
+
9
13
  it { should ensure_length_at_least(:zip, 5) }
14
+ it { should_not ensure_length_at_least(:zip, 4) }
15
+ it { should_not ensure_length_at_least(:zip, 6) }
16
+
17
+ it { should validate_length_of(:zip, :minimum => 5) }
18
+ it { should validate_length_of(:zip, :minimum => 5).allow_nil }
19
+ it { should_not validate_length_of(:zip, :is => 5) }
20
+ it { should_not validate_length_of(:zip, :minimum => 5, :allow_nil => false) }
21
+ it { should_not validate_length_of(:zip, :minimum => 4) }
22
+ it { should_not validate_length_of(:zip, :minimum => 6) }
23
+
24
+ it { proc{ should validate_length_of(:zip) }.should raise_error }
25
+
10
26
  it { should only_allow_numeric_values_for(:zip) }
27
+ it { should validate_numericality_of(:zip).less_than(20) }
28
+ it { should validate_numericality_of(:zip).greater_than(10) }
29
+ it { should validate_numericality_of(:zip).less_than(20).greater_than(10) }
30
+ it { should_not validate_numericality_of(:zip, :less_than => 10) }
31
+ it { should_not validate_numericality_of(:zip, :greater_than => 20) }
32
+
33
+ it { should_not only_allow_numeric_values_for(:title) }
34
+ it { should_not only_allow_numeric_or_blank_values_for(:zip) }
11
35
  end
12
36
 
13
37
  describe Address do
@@ -16,6 +40,26 @@ describe Address do
16
40
  should_belong_to :addressable
17
41
 
18
42
  should_require_unique_attributes :title, :scoped_to => [:addressable_id, :addressable_type]
43
+ should_not_require_unique_attributes :zip
44
+
19
45
  should_ensure_length_at_least :zip, 5
46
+ should_not_ensure_length_at_least :zip, 4
47
+ should_not_ensure_length_at_least :zip, 6
48
+
49
+ should_validate_length_of :zip, :minimum => 5
50
+ should_validate_length_of :zip, :minimum => 5, :allow_nil => true
51
+ should_not_validate_length_of :zip, :minimum => 5, :allow_nil => false
52
+ should_not_validate_length_of :zip, :is => 5
53
+ should_not_validate_length_of :zip, :minimum => 4
54
+ should_not_validate_length_of :zip, :minimum => 6
55
+
20
56
  should_only_allow_numeric_values_for :zip
57
+ should_validate_numericality_of :zip, :less_than => 20
58
+ should_validate_numericality_of :zip, :greater_than => 10
59
+ should_validate_numericality_of :zip, :less_than => 20, :greater_than => 10
60
+ should_not_validate_numericality_of :zip, :less_than => 10
61
+ should_not_validate_numericality_of :zip, :greater_than => 20
62
+
63
+ should_not_only_allow_numeric_values_for :title
64
+ should_not_only_allow_numeric_or_blank_values_for :zip
21
65
  end
@@ -1,17 +1,78 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe Dog do
3
+ describe Pets::Dog do
4
4
  it { should belong_to(:user) }
5
5
  it { should belong_to(:address) }
6
6
  it { should belong_to(:user, :address) }
7
-
7
+ it { should_not belong_to(:foo, :bar) }
8
+
8
9
  it { should have_and_belong_to_many(:fleas) }
10
+
11
+ it { should only_allow_numeric_values_for(:age).allow_blank }
12
+ it { should only_allow_numeric_values_for(:age).allow_blank(true) }
13
+ it { should only_allow_numeric_values_for(:age, :allow_blank => true) }
14
+
15
+ it { should_not only_allow_numeric_values_for(:age).allow_blank(false) }
16
+ it { should_not only_allow_numeric_values_for(:age, :allow_blank => false) }
17
+
18
+ it { should only_allow_numeric_or_blank_values_for(:age) }
19
+
20
+ it { should require_attributes(:owner_id) }
21
+
22
+ it { should validate_numericality_of(:age) }
23
+ it { should validate_numericality_of(:age).only_integer }
24
+ it { should validate_numericality_of(:age).allow_blank(true) }
25
+ it { should validate_numericality_of(:age).odd }
26
+ it { should validate_numericality_of(:age).even(false) }
27
+ it { should validate_numericality_of(:age).greater_than_or_equal_to(10) }
28
+
29
+ it { should_not validate_numericality_of(:age, :greater_than_or_equal_to => 9) }
30
+ it { should_not validate_numericality_of(:age, :only_integer => false) }
31
+ it { should_not validate_numericality_of(:age, :allow_blank => false) }
32
+ it { should_not validate_numericality_of(:age).odd(false) }
33
+ it { should_not validate_numericality_of(:age).even }
34
+
35
+ it { should validate_numericality_of(:owner_id) }
36
+ it { should validate_numericality_of(:owner_id).only_integer(false) }
37
+ it { should validate_numericality_of(:owner_id).allow_nil }
38
+ it { should validate_numericality_of(:owner_id).odd(false) }
39
+ it { should validate_numericality_of(:owner_id).even }
40
+ it { should validate_numericality_of(:owner_id).less_than_or_equal_to(10) }
41
+
42
+ it { should_not validate_numericality_of(:owner_id, :less_than_or_equal_to => 11) }
43
+ it { should_not validate_numericality_of(:owner_id, :only_integer => true) }
44
+ it { should_not validate_numericality_of(:owner_id, :allow_nil => false) }
45
+ it { should_not validate_numericality_of(:owner_id).odd }
46
+ it { should_not validate_numericality_of(:owner_id).even(false) }
9
47
  end
10
48
 
11
- describe Dog do
49
+ describe Pets::Dog do
12
50
  should_belong_to :user
13
51
  should_belong_to :address
14
52
  should_belong_to :user, :address
53
+ should_not_belong_to :foo, :bar
15
54
 
16
55
  should_have_and_belong_to_many :fleas
56
+
57
+ should_only_allow_numeric_or_blank_values_for :age
58
+ should_only_allow_numeric_values_for :age, :allow_blank => true
59
+ should_not_only_allow_numeric_values_for :age, :allow_blank => false
60
+
61
+ should_require_attributes :owner_id
62
+
63
+ should_validate_numericality_of :owner_id
64
+ should_validate_numericality_of :owner_id, :allow_nil => true
65
+ should_validate_numericality_of :owner_id, :even => true
66
+ should_validate_numericality_of :owner_id, :less_than_or_equal_to => 10
67
+ should_not_validate_numericality_of :owner_id, :less_than_or_equal_to => 11
68
+ should_not_validate_numericality_of :owner_id, :odd => true
69
+ should_not_validate_numericality_of :owner_id, :allow_nil => false
70
+
71
+ should_validate_numericality_of :age
72
+ should_validate_numericality_of :age, :allow_blank => true
73
+ should_validate_numericality_of :age, :odd => true
74
+ should_validate_numericality_of :age, :greater_than_or_equal_to => 10
75
+ should_not_validate_numericality_of :age, :greater_than_or_equal_to => 9
76
+ should_not_validate_numericality_of :age, :even => true
77
+ should_not_validate_numericality_of :age, :allow_blank => false
17
78
  end
@@ -1,9 +1,39 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Flea do
4
+ fixtures :fleas
5
+
4
6
  it { should have_and_belong_to_many(:dogs) }
7
+
8
+ describe "with valid attributes" do
9
+ subject { Flea.new(:name => 'Mike') }
10
+ it { should be_valid }
11
+ end
12
+
13
+ describe "without a name" do
14
+ subject { Flea.new(:name => '') }
15
+ it { should_not be_valid }
16
+ end
17
+
18
+ it { should validate_uniqueness_of :name, :case_sensitive => false }
19
+ it { should validate_uniqueness_of :color, :allow_nil => true }
20
+ it { should validate_uniqueness_of :address, :allow_blank => true }
21
+
22
+ it { should_not validate_uniqueness_of :name, :case_sensitive => true }
23
+ it { should_not validate_uniqueness_of :color, :allow_nil => false }
24
+ it { should_not validate_uniqueness_of :address, :allow_blank => false }
5
25
  end
6
26
 
7
27
  describe Flea do
28
+ fixtures :fleas
29
+
8
30
  should_have_and_belong_to_many :dogs
31
+
32
+ should_validate_uniqueness_of :name, :case_sensitive => false
33
+ should_validate_uniqueness_of :color, :allow_nil => true
34
+ should_validate_uniqueness_of :address, :allow_blank => true
35
+
36
+ should_not_validate_uniqueness_of :name, :case_sensitive => true
37
+ should_not_validate_uniqueness_of :color, :allow_nil => false
38
+ should_not_validate_uniqueness_of :address, :allow_blank => false
9
39
  end