remockable 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -17,13 +17,34 @@ Remockable was born. It's an attempt to start with a clean slate but maintain
17
17
  the original goal of Remarkable in spirit.
18
18
 
19
19
 
20
- ## Matchers
21
-
22
- Remockable currently includes support for all of the Active Model validation
23
- and allow_mass_assignment_of matchers, and also supports the association,
24
- have_column, have_index, and have_scope Active Record matchers.
25
-
26
- More are on the way soon.
20
+ ## Active Model Matchers
21
+
22
+ The following Active Model matchers are supported:
23
+
24
+ * allow_mass_assignment_of
25
+ * validate_acceptance_of
26
+ * validate_confirmation_of
27
+ * validate_exclusion_of
28
+ * validate_format_of
29
+ * validate_inclusion_of
30
+ * validate_length_of
31
+ * validate_numericality_of
32
+ * validate_presence_of
33
+
34
+
35
+ ## Active Record Matchers
36
+
37
+ The following Active Record matchers are supported:
38
+
39
+ * have_column
40
+ * have_index
41
+ * have_scope
42
+ * belongs_to
43
+ * have_one
44
+ * have_many
45
+ * have_and_belong_to_many
46
+ * validate_associated
47
+ * validate_uniqueness_of
27
48
 
28
49
 
29
50
  ## Installation
@@ -0,0 +1,29 @@
1
+ RSpec::Matchers.define(:validate_associated) do |*attributes|
2
+ extend Remockable::ActiveModel::Helpers
3
+
4
+ @type = :associated
5
+ @expected = attributes.extract_options!
6
+ @attributes = attributes
7
+
8
+ unsupported_options %w(if unless)
9
+ valid_options %w(message on)
10
+
11
+ match do |actual|
12
+ validate_attributes do |validator|
13
+ validator && validator.options.slice(*expected.keys) == expected
14
+ end
15
+ end
16
+
17
+ failure_message_for_should do |actual|
18
+ "Expected #{subject.class.name} to #{description}"
19
+ end
20
+
21
+ failure_message_for_should_not do |actual|
22
+ "Did not expect #{subject.class.name} to #{description}"
23
+ end
24
+
25
+ description do
26
+ with = " with #{expected.inspect}" if expected.any?
27
+ "validate #{type} #{@attributes.to_sentence}#{with}"
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ RSpec::Matchers.define(:validate_uniqueness_of) do |*attributes|
2
+ extend Remockable::ActiveModel::Helpers
3
+
4
+ @type = :uniqueness
5
+ @expected = attributes.extract_options!
6
+ @attributes = attributes
7
+
8
+ unsupported_options %w(if unless)
9
+ valid_options %w(allow_nil allow_blank case_sensitive message scope)
10
+
11
+ match do |actual|
12
+ validate_attributes do |validator|
13
+ validator && validator.options.slice(*expected.keys) == expected
14
+ end
15
+ end
16
+
17
+ failure_message_for_should do |actual|
18
+ "Expected #{subject.class.name} to #{description}"
19
+ end
20
+
21
+ failure_message_for_should_not do |actual|
22
+ "Did not expect #{subject.class.name} to #{description}"
23
+ end
24
+
25
+ description do
26
+ with = " with #{expected.inspect}" if expected.any?
27
+ "validate #{type} of #{@attributes.to_sentence}#{with}"
28
+ end
29
+ end
@@ -8,3 +8,6 @@ require 'remockable/active_record/have_one'
8
8
  require 'remockable/active_record/have_column'
9
9
  require 'remockable/active_record/have_index'
10
10
  require 'remockable/active_record/have_scope'
11
+
12
+ require 'remockable/active_record/validate_associated'
13
+ require 'remockable/active_record/validate_uniqueness_of'
@@ -1,3 +1,3 @@
1
1
  module Remockable
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: remockable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tyler Hunt
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-07 00:00:00 -04:00
13
+ date: 2011-05-09 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -120,6 +120,8 @@ files:
120
120
  - lib/remockable/active_record/have_one.rb
121
121
  - lib/remockable/active_record/have_scope.rb
122
122
  - lib/remockable/active_record/helpers.rb
123
+ - lib/remockable/active_record/validate_associated.rb
124
+ - lib/remockable/active_record/validate_uniqueness_of.rb
123
125
  - lib/remockable/active_record.rb
124
126
  - lib/remockable/helpers.rb
125
127
  - lib/remockable/version.rb