remockable 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ module Remockable
2
+ module ActiveModel
3
+ module Helpers
4
+ include Remockable::Helpers
5
+
6
+ attr_reader :type
7
+
8
+ def validator_for(attribute)
9
+ subject.class.validators_on(attribute).detect do |validator|
10
+ validator.kind == type
11
+ end
12
+ end
13
+
14
+ def validate_attributes
15
+ @attributes.inject(true) do |result, attribute|
16
+ yield validator_for(attribute)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_acceptance_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :acceptance
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_confirmation_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :confirmation
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_exclusion_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :exclusion
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_format_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :format
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_inclusion_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :inclusion
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_length_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :length
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_numericality_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :numericality
5
5
  @expected = attributes.extract_options!
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:validate_presence_of) do |*attributes|
2
- extend Remockable::Helpers
2
+ extend Remockable::ActiveModel::Helpers
3
3
 
4
4
  @type = :presence
5
5
  @expected = attributes.extract_options!
@@ -0,0 +1,9 @@
1
+ require 'remockable/active_model/helpers'
2
+ require 'remockable/active_model/validate_acceptance_of'
3
+ require 'remockable/active_model/validate_confirmation_of'
4
+ require 'remockable/active_model/validate_exclusion_of'
5
+ require 'remockable/active_model/validate_format_of'
6
+ require 'remockable/active_model/validate_inclusion_of'
7
+ require 'remockable/active_model/validate_length_of'
8
+ require 'remockable/active_model/validate_numericality_of'
9
+ require 'remockable/active_model/validate_presence_of'
@@ -0,0 +1,27 @@
1
+ RSpec::Matchers.define(:have_column) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @column = attributes.first
6
+
7
+ valid_options %w(default limit null precision scale type)
8
+
9
+ match do |actual|
10
+ if column = subject.columns.detect { |column| column.name == @column.to_s }
11
+ @expected.all? { |key, value| column.send(key).should == value }
12
+ end
13
+ end
14
+
15
+ failure_message_for_should do |actual|
16
+ "Expected #{subject.class.name} to #{description}"
17
+ end
18
+
19
+ failure_message_for_should_not do |actual|
20
+ "Did not expect #{subject.class.name} to #{description}"
21
+ end
22
+
23
+ description do
24
+ with = " with #{expected.inspect}" if expected.any?
25
+ "have column #{@column}#{with}"
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ RSpec::Matchers.define(:have_index) do |*attributes|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = attributes.extract_options!
5
+ @columns = attributes
6
+
7
+ valid_options %w(name unique)
8
+
9
+ match do |actual|
10
+ name = @expected[:name]
11
+ unique = @expected[:unique]
12
+ indexes = ActiveRecord::Base.connection.indexes(subject.table_name)
13
+
14
+ column_names = @columns.flatten.collect(&:to_s)
15
+
16
+ index = indexes.detect do |index|
17
+ if column_names.any?
18
+ index.columns == column_names
19
+ elsif name
20
+ matches_name?(index, name)
21
+ end
22
+ end
23
+
24
+ if index
25
+ name_matches = name.nil? || matches_name?(index, name)
26
+ unique_matches = unique.nil? || index.unique == unique
27
+
28
+ name_matches && unique_matches
29
+ end
30
+ end
31
+
32
+ def matches_name?(index, name)
33
+ index.name == name.to_s
34
+ end
35
+
36
+ failure_message_for_should do |actual|
37
+ "Expected #{subject.class.name} to #{description}"
38
+ end
39
+
40
+ failure_message_for_should_not do |actual|
41
+ "Did not expect #{subject.class.name} to #{description}"
42
+ end
43
+
44
+ description do
45
+ with = " with #{expected.inspect}" if expected.any?
46
+ "have index on #{@columns.to_sentence}#{with}"
47
+ end
48
+ end
@@ -0,0 +1,79 @@
1
+ RSpec::Matchers.define(:have_scope) do |*expected|
2
+ extend Remockable::ActiveRecord::Helpers
3
+
4
+ @expected = expected.extract_options!
5
+ @name = expected.first
6
+
7
+ valid_options %w(with)
8
+
9
+ match do |actual|
10
+ if subject.class.respond_to?(@name)
11
+ @scope = if @expected.key?(:with)
12
+ with = Array(@expected[:with])
13
+ subject.class.send(@name, *with)
14
+ else
15
+ subject.class.send(@name)
16
+ end
17
+
18
+ if @scope.is_a?(ActiveRecord::Relation)
19
+ if @relation
20
+ query_matches = @scope.arel.to_sql == @relation.arel.to_sql
21
+ eager_load_matches = @scope.eager_load_values == @relation.eager_load_values
22
+ includes_matches = @scope.includes_values == @relation.includes_values
23
+ lock_matches = @scope.lock_value == @relation.lock_value
24
+ preload_matches = @scope.preload_values == @relation.preload_values
25
+ readonly_matches = @scope.readonly_value == @relation.readonly_value
26
+
27
+ query_matches && eager_load_matches && includes_matches && lock_matches && preload_matches && readonly_matches
28
+ else
29
+ true
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def method_missing(method, *args, &block)
36
+ unsupposed_query_methods = %(
37
+ create_with
38
+ )
39
+
40
+ query_methods = %w(
41
+ eager_load
42
+ from
43
+ group
44
+ having
45
+ includes
46
+ joins
47
+ limit
48
+ lock
49
+ offset
50
+ order
51
+ preload
52
+ readonly
53
+ reorder
54
+ select
55
+ where
56
+ )
57
+
58
+ if query_methods.include?(method.to_s)
59
+ @relation ||= subject.class.scoped
60
+ @relation = @relation.send(method, *args)
61
+ self
62
+ else
63
+ super
64
+ end
65
+ end
66
+
67
+ failure_message_for_should do |actual|
68
+ "Expected #{subject.class.name} to #{description}"
69
+ end
70
+
71
+ failure_message_for_should_not do |actual|
72
+ "Did not expect #{subject.class.name} to #{description}"
73
+ end
74
+
75
+ description do
76
+ with = " with #{@expected.inspect}" if @expected.any?
77
+ "have scope #{@name}#{with}"
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ module Remockable
2
+ module ActiveRecord
3
+ module Helpers
4
+ include Remockable::Helpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'remockable/active_record/helpers'
2
+ require 'remockable/active_record/have_column'
3
+ require 'remockable/active_record/have_index'
4
+ require 'remockable/active_record/have_scope'
@@ -1,7 +1,5 @@
1
1
  module Remockable
2
2
  module Helpers
3
- attr_reader :type
4
-
5
3
  def unsupported_options(keys)
6
4
  @expected.keys.each do |key|
7
5
  if keys.collect(&:to_sym).include?(key.to_sym)
@@ -17,17 +15,5 @@ module Remockable
17
15
  end
18
16
  end
19
17
  end
20
-
21
- def validator_for(attribute)
22
- subject.class.validators_on(attribute).detect do |validator|
23
- validator.kind == type
24
- end
25
- end
26
-
27
- def validate_attributes
28
- @attributes.inject(true) do |result, attribute|
29
- yield validator_for(attribute)
30
- end
31
- end
32
18
  end
33
19
  end
data/lib/remockable.rb CHANGED
@@ -1,2 +1,8 @@
1
+ require 'rspec/core'
2
+ require 'active_support/core_ext/array/extract_options'
3
+ require 'active_support/core_ext/hash/slice'
4
+ require 'active_support/core_ext/object/try'
5
+
1
6
  require 'remockable/helpers'
2
- require 'remockable/matchers'
7
+ require 'remockable/active_model'
8
+ require 'remockable/active_record'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tyler Hunt
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-21 00:00:00 -05:00
17
+ date: 2011-03-11 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: activesupport
36
+ name: activerecord
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -48,7 +48,7 @@ dependencies:
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
- name: rspec-core
51
+ name: activesupport
52
52
  prerelease: false
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -56,13 +56,14 @@ dependencies:
56
56
  - - ~>
57
57
  - !ruby/object:Gem::Version
58
58
  segments:
59
- - 2
59
+ - 3
60
60
  - 0
61
- version: "2.0"
61
+ - 0
62
+ version: 3.0.0
62
63
  type: :runtime
63
64
  version_requirements: *id003
64
65
  - !ruby/object:Gem::Dependency
65
- name: rspec-expectations
66
+ name: rspec-core
66
67
  prerelease: false
67
68
  requirement: &id004 !ruby/object:Gem::Requirement
68
69
  none: false
@@ -76,7 +77,7 @@ dependencies:
76
77
  type: :runtime
77
78
  version_requirements: *id004
78
79
  - !ruby/object:Gem::Dependency
79
- name: rspec-mocks
80
+ name: rspec-expectations
80
81
  prerelease: false
81
82
  requirement: &id005 !ruby/object:Gem::Requirement
82
83
  none: false
@@ -87,8 +88,37 @@ dependencies:
87
88
  - 2
88
89
  - 0
89
90
  version: "2.0"
90
- type: :development
91
+ type: :runtime
91
92
  version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: rspec-mocks
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 2
103
+ - 0
104
+ version: "2.0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: sqlite3
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ segments:
116
+ - 1
117
+ - 3
118
+ - 3
119
+ version: 1.3.3
120
+ type: :development
121
+ version_requirements: *id007
92
122
  description:
93
123
  email:
94
124
  executables: []
@@ -98,18 +128,23 @@ extensions: []
98
128
  extra_rdoc_files: []
99
129
 
100
130
  files:
101
- - README
102
131
  - LICENSE
132
+ - lib/remockable/active_model/helpers.rb
133
+ - lib/remockable/active_model/validate_acceptance_of.rb
134
+ - lib/remockable/active_model/validate_confirmation_of.rb
135
+ - lib/remockable/active_model/validate_exclusion_of.rb
136
+ - lib/remockable/active_model/validate_format_of.rb
137
+ - lib/remockable/active_model/validate_inclusion_of.rb
138
+ - lib/remockable/active_model/validate_length_of.rb
139
+ - lib/remockable/active_model/validate_numericality_of.rb
140
+ - lib/remockable/active_model/validate_presence_of.rb
141
+ - lib/remockable/active_model.rb
142
+ - lib/remockable/active_record/have_column.rb
143
+ - lib/remockable/active_record/have_index.rb
144
+ - lib/remockable/active_record/have_scope.rb
145
+ - lib/remockable/active_record/helpers.rb
146
+ - lib/remockable/active_record.rb
103
147
  - lib/remockable/helpers.rb
104
- - lib/remockable/matchers/validate_acceptance_of.rb
105
- - lib/remockable/matchers/validate_confirmation_of.rb
106
- - lib/remockable/matchers/validate_exclusion_of.rb
107
- - lib/remockable/matchers/validate_format_of.rb
108
- - lib/remockable/matchers/validate_inclusion_of.rb
109
- - lib/remockable/matchers/validate_length_of.rb
110
- - lib/remockable/matchers/validate_numericality_of.rb
111
- - lib/remockable/matchers/validate_presence_of.rb
112
- - lib/remockable/matchers.rb
113
148
  - lib/remockable.rb
114
149
  has_rdoc: true
115
150
  homepage: http://github.com/tylerhunt/remockable
data/README DELETED
@@ -1,23 +0,0 @@
1
- Remockable
2
- ==========
3
-
4
- A collection of RSpec matchers to simplify your web app specs.
5
-
6
- The goal of this project is to provide a modern replacement to the now
7
- unmaintained Remarkable project. Remarkable was a great asset when Rails 2.3
8
- was current, but now that Rails 3.0 has become mainstream, a gap has been left
9
- by still unreleased Remarkable 4.0. In looking at the code for Remarkable to
10
- determine the feasibility of continuing work on Remarkable itself, it seems
11
- clear that the scope of that project has outgrown its usefulness for most users.
12
- It was with this conclusion in mind that Remockable was born. It's an attempt to
13
- start with a clean slate but maintain the original goal of Remarkable in spirit.
14
-
15
-
16
- Matchers
17
- ========
18
-
19
- In this first release of Remockable, there are matchers for all of the Active
20
- Model validations. More are on the way soon.
21
-
22
-
23
- Copyright (c) 2010-2011 Tyler Hunt, released under the MIT license
@@ -1,13 +0,0 @@
1
- require 'rspec/core'
2
- require 'active_support/core_ext/array/extract_options'
3
- require 'active_support/core_ext/hash/slice'
4
- require 'active_support/core_ext/object/try'
5
-
6
- require 'remockable/matchers/validate_acceptance_of'
7
- require 'remockable/matchers/validate_confirmation_of'
8
- require 'remockable/matchers/validate_exclusion_of'
9
- require 'remockable/matchers/validate_format_of'
10
- require 'remockable/matchers/validate_inclusion_of'
11
- require 'remockable/matchers/validate_length_of'
12
- require 'remockable/matchers/validate_numericality_of'
13
- require 'remockable/matchers/validate_presence_of'