rspectacular 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.
data/lib/rspectacular.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  if defined? RSpec
2
- require 'rspectacular/active_record'
2
+ require 'rspectacular/rspec'
3
3
  end
File without changes
@@ -1,41 +1,47 @@
1
- class DateRangeMatcher
2
- include Shoulda::ActiveRecord::Helpers
3
-
4
- def initialize(dates)
5
- @begin_field = dates[:from].to_s
6
- @end_field = dates[:to].to_s
7
-
8
- @begin_method = "#{dates[:from].to_s}=".to_sym
9
- @end_method = "#{dates[:to].to_s}=".to_sym
10
- end
11
-
12
- def matches?(rangeable)
13
- @rangeable = rangeable
14
- beginning_date = Date.today
15
- ending_date = Date.today - 1
16
-
17
- rangeable.send(@begin_method, beginning_date)
18
- rangeable.send(@end_method, ending_date)
19
-
20
- rangeable.valid?
21
-
22
- rangeable.errors[@begin_field].include?("must be on or before #{ending_date.to_s}") &&
23
- rangeable.errors[@end_field].include?("must be on or after #{beginning_date.to_s}")
1
+ module RSpectacular
2
+ module ActiveRecord
3
+ module Matchers
4
+ class DateRangeMatcher
5
+ include Shoulda::ActiveRecord::Helpers
6
+
7
+ def initialize(dates)
8
+ @begin_field = dates[:from].to_s
9
+ @end_field = dates[:to].to_s
10
+
11
+ @begin_method = "#{dates[:from].to_s}=".to_sym
12
+ @end_method = "#{dates[:to].to_s}=".to_sym
13
+ end
14
+
15
+ def matches?(rangeable)
16
+ @rangeable = rangeable
17
+ beginning_date = Date.today
18
+ ending_date = Date.today - 1
19
+
20
+ rangeable.send(@begin_method, beginning_date)
21
+ rangeable.send(@end_method, ending_date)
22
+
23
+ rangeable.valid?
24
+
25
+ rangeable.errors[@begin_field].include?("must be on or before #{ending_date.to_s}") &&
26
+ rangeable.errors[@end_field].include?("must be on or after #{beginning_date.to_s}")
27
+ end
28
+
29
+ def failure_message
30
+ "#{@rangeable_class} should only accept a valid date range from #{@begin_field} to #{@end_field}, got: #{pretty_error_messages(@rangeable)}"
31
+ end
32
+
33
+ def negative_failure_message
34
+ "#{@rangeable_class} shouldn't accept a valid date range from #{@begin_field} to #{@end_field}, got: #{pretty_error_messages(@rangeable)}"
35
+ end
36
+
37
+ def description
38
+ "should be contain a valid range for #{@rangeable_class}"
39
+ end
40
+ end
41
+
42
+ def validate_date_range(dates)
43
+ DateRangeMatcher.new(dates)
44
+ end
45
+ end
24
46
  end
25
-
26
- def failure_message
27
- "#{@rangeable_class} should only accept a valid date range from #{@begin_field} to #{@end_field}, got: #{pretty_error_messages(@rangeable)}"
28
- end
29
-
30
- def negative_failure_message
31
- "#{@rangeable_class} shouldn't accept a valid date range from #{@begin_field} to #{@end_field}, got: #{pretty_error_messages(@rangeable)}"
32
- end
33
-
34
- def description
35
- "should be contain a valid range for #{@rangeable_class}"
36
- end
37
- end
38
-
39
- def validate_date_range(dates)
40
- DateRangeMatcher.new(dates)
41
47
  end
@@ -1,33 +1,39 @@
1
- class DatelinessMatcher
2
- include Shoulda::ActiveRecord::Helpers
3
-
4
- def initialize(date_field)
5
- @date_field = date_field.to_s
6
- @date_method = "#{date_field.to_s}=".to_sym
7
- end
8
-
9
- def matches?(dateable)
10
- @dateable = dateable
11
- dateable.send(@date_method, Date.today)
12
-
13
- dateable.valid?
14
-
15
- !dateable.errors[@date_field].include?("is not a valid date")
16
- end
17
-
18
- def failure_message
19
- "Expected #{@date_field} to contain a valid date, got: #{pretty_error_messages(@dateable)}"
1
+ module RSpectacular
2
+ module ActiveRecord
3
+ module Matchers
4
+ class DatelinessMatcher
5
+ include Shoulda::ActiveRecord::Helpers
6
+
7
+ def initialize(date_field)
8
+ @date_field = date_field.to_s
9
+ @date_method = "#{date_field.to_s}=".to_sym
10
+ end
11
+
12
+ def matches?(dateable)
13
+ @dateable = dateable
14
+ dateable.send(@date_method, Date.today)
15
+
16
+ dateable.valid?
17
+
18
+ !dateable.errors[@date_field].include?("is not a valid date")
19
+ end
20
+
21
+ def failure_message
22
+ "Expected #{@date_field} to contain a valid date, got: #{pretty_error_messages(@dateable)}"
23
+ end
24
+
25
+ def negative_failure_message
26
+ "Expected #{@date_field} to contain an invalid date, got: #{pretty_error_messages(@dateable)}"
27
+ end
28
+
29
+ def description
30
+ "should be contain a valid date"
31
+ end
32
+ end
33
+
34
+ def validate_dateliness_of(date)
35
+ DatelinessMatcher.new(date)
36
+ end
37
+ end
20
38
  end
21
-
22
- def negative_failure_message
23
- "Expected #{@date_field} to contain an invalid date, got: #{pretty_error_messages(@dateable)}"
24
- end
25
-
26
- def description
27
- "should be contain a valid date"
28
- end
29
- end
30
-
31
- def validate_dateliness_of(date)
32
- DatelinessMatcher.new(date)
33
39
  end
@@ -1,29 +1,35 @@
1
- class PersistenceMatcher
2
- def initialize(persistable_object)
3
- @persistable_class = persistable_object.class
4
- @desired_attributes = persistable_object.is_a?(Hash) ? persistable_object : persistable_object.attributes
5
- @desired_attributes = @desired_attributes.reject {|k,v| ['id', 'created_at', 'updated_at'].include? k}
6
- end
1
+ module RSpectacular
2
+ module ActiveRecord
3
+ module Matchers
4
+ class PersistenceMatcher
5
+ def initialize(persistable_object)
6
+ @persistable_class = persistable_object.class
7
+ @desired_attributes = persistable_object.is_a?(Hash) ? persistable_object : persistable_object.attributes
8
+ @desired_attributes = @desired_attributes.reject {|k,v| ['id', 'created_at', 'updated_at'].include? k}
9
+ end
7
10
 
8
- def matches?(subject)
9
- @persistable_class.where(@desired_attributes).first
10
- end
11
+ def matches?(subject)
12
+ @persistable_class.where(@desired_attributes).first
13
+ end
11
14
 
12
- def failure_message
13
- "Expected to find an object saved with #{@desired_attributes}, didn't find one."
14
- end
15
+ def failure_message
16
+ "Expected to find an object saved with #{@desired_attributes}, didn't find one."
17
+ end
15
18
 
16
- def negative_failure_message
17
- "Didn't expect to find an object saved with #{@desired_attributes}, but got one anyway"
18
- end
19
+ def negative_failure_message
20
+ "Didn't expect to find an object saved with #{@desired_attributes}, but got one anyway"
21
+ end
19
22
 
20
- def description
21
- "should be an instance of #{@expected_class_name}"
22
- end
23
- end
23
+ def description
24
+ "should be an instance of #{@expected_class_name}"
25
+ end
26
+ end
24
27
 
25
- def persist(desired_object)
26
- PersistenceMatcher.new(desired_object)
27
- end
28
+ def persist(desired_object)
29
+ PersistenceMatcher.new(desired_object)
30
+ end
28
31
 
29
- alias :persist_the :persist
32
+ alias :persist_the :persist
33
+ end
34
+ end
35
+ end
@@ -1,33 +1,39 @@
1
- class PositivityMatcher < Shoulda::ActiveRecord::Matchers::ValidateNumericalityOfMatcher
2
- def matches?(positivitable)
3
- super(positivitable)
1
+ module RSpectacular
2
+ module ActiveRecord
3
+ module Matchers
4
+ class PositivityMatcher < Shoulda::ActiveRecord::Matchers::ValidateNumericalityOfMatcher
5
+ def matches?(positivitable)
6
+ super(positivitable)
4
7
 
5
- disallows_zero_values &&
6
- disallows_negative_values
7
- end
8
+ disallows_zero_values &&
9
+ disallows_negative_values
10
+ end
8
11
 
9
- def failure_message
10
- "Expected #{@attribute.to_s} to be a positive number, got: #{pretty_error_messages(@attribute)}"
11
- end
12
+ def failure_message
13
+ "Expected #{@attribute.to_s} to be a positive number, got: #{pretty_error_messages(@attribute)}"
14
+ end
12
15
 
13
- def negative_failure_message
14
- "Expected #{@attribute.to_s} to be a negative number, got: #{pretty_error_messages(@attribute)}"
15
- end
16
+ def negative_failure_message
17
+ "Expected #{@attribute.to_s} to be a negative number, got: #{pretty_error_messages(@attribute)}"
18
+ end
16
19
 
17
- def disallows_negative_values
18
- disallows_value_of(-1) &&
19
- disallows_value_of(-100)
20
- end
20
+ def disallows_negative_values
21
+ disallows_value_of(-1) &&
22
+ disallows_value_of(-100)
23
+ end
21
24
 
22
- def disallows_zero_values
23
- disallows_value_of(0)
24
- end
25
+ def disallows_zero_values
26
+ disallows_value_of(0)
27
+ end
25
28
 
26
- def description
27
- "should be contain a positive number"
28
- end
29
- end
29
+ def description
30
+ "should be contain a positive number"
31
+ end
32
+ end
30
33
 
31
- def validate_positivity_of(date)
32
- PositivityMatcher.new(date)
34
+ def validate_positivity_of(date)
35
+ PositivityMatcher.new(date)
36
+ end
37
+ end
38
+ end
33
39
  end
@@ -1,29 +1,35 @@
1
- class TruthfulnessMatcher < Shoulda::ActiveRecord::Matchers::ValidationMatcher
2
- def matches?(truthable)
3
- super(truthable)
1
+ module RSpectacular
2
+ module ActiveRecord
3
+ module Matchers
4
+ class TruthfulnessMatcher < Shoulda::ActiveRecord::Matchers::ValidationMatcher
5
+ def matches?(truthable)
6
+ super(truthable)
4
7
 
5
- allows_true &&
6
- allows_false &&
7
- disallows_nil
8
- end
8
+ allows_true &&
9
+ allows_false &&
10
+ disallows_nil
11
+ end
9
12
 
10
- def allows_true
11
- allows_value_of(true)
12
- end
13
+ def allows_true
14
+ allows_value_of(true)
15
+ end
13
16
 
14
- def allows_false
15
- allows_value_of(false)
16
- end
17
+ def allows_false
18
+ allows_value_of(false)
19
+ end
17
20
 
18
- def disallows_nil
19
- disallows_value_of(nil)
20
- end
21
+ def disallows_nil
22
+ disallows_value_of(nil)
23
+ end
21
24
 
22
- def description
23
- "should accept only boolean true or false values"
24
- end
25
- end
25
+ def description
26
+ "should accept only boolean true or false values"
27
+ end
28
+ end
26
29
 
27
- def validate_truthfulness_of(truthteller)
28
- TruthfulnessMatcher.new(truthteller)
30
+ def validate_truthfulness_of(truthteller)
31
+ TruthfulnessMatcher.new(truthteller)
32
+ end
33
+ end
34
+ end
29
35
  end
@@ -0,0 +1,17 @@
1
+ require 'rspectacular/active_record/matchers'
2
+
3
+ module RSpec
4
+ module Matchers
5
+ include RSpectacular::ActiveRecord::Matchers
6
+ end
7
+
8
+ # module Rails
9
+ # module ControllerExampleGroup
10
+ # include Shoulda::ActionController::Matchers
11
+ # end
12
+
13
+ # module MailerExampleGroup
14
+ # include Shoulda::ActionMailer::Matchers
15
+ # end
16
+ # end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Rspectacular
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/rspectacular.gemspec CHANGED
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('shoulda', '~> 2.11.0')
21
23
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspectacular
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.0.2
10
6
  platform: ruby
11
7
  authors:
12
8
  - jfelchner
@@ -15,10 +11,20 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-01-30 00:00:00 -06:00
14
+ date: 2011-05-12 00:00:00 -05:00
19
15
  default_executable:
20
- dependencies: []
21
-
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: shoulda
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: 2.11.0
26
+ type: :runtime
27
+ version_requirements: *id001
22
28
  description: We rock some custom RSpec matchers like it ain't nobody's bidnezz.
23
29
  email:
24
30
  - support@thekompanee.com
@@ -33,13 +39,14 @@ files:
33
39
  - Gemfile
34
40
  - Rakefile
35
41
  - lib/rspectacular.rb
42
+ - lib/rspectacular/active_record.rb
36
43
  - lib/rspectacular/active_record/date_range_matcher.rb
37
44
  - lib/rspectacular/active_record/dateliness_matcher.rb
38
45
  - lib/rspectacular/active_record/matchers.rb
39
46
  - lib/rspectacular/active_record/persistence_matcher.rb
40
47
  - lib/rspectacular/active_record/positivity_matcher.rb
41
48
  - lib/rspectacular/active_record/truthfulness_matcher.rb
42
- - lib/rspectacular/matchers.rb
49
+ - lib/rspectacular/rspec.rb
43
50
  - lib/rspectacular/version.rb
44
51
  - rails/init.rb
45
52
  - rspectacular.gemspec
@@ -57,21 +64,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
64
  requirements:
58
65
  - - ">="
59
66
  - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
67
  version: "0"
63
68
  required_rubygems_version: !ruby/object:Gem::Requirement
64
69
  none: false
65
70
  requirements:
66
71
  - - ">="
67
72
  - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
73
  version: "0"
71
74
  requirements: []
72
75
 
73
76
  rubyforge_project: rspectacular
74
- rubygems_version: 1.3.7
77
+ rubygems_version: 1.6.2
75
78
  signing_key:
76
79
  specification_version: 3
77
80
  summary: Custom RSpec matchers