regressor 0.5.7 → 0.5.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b17c0573da2b281d3b36644b43252f74b4aae2e
4
- data.tar.gz: 65c31a48fd1018e171dd8d18a5cd1801be6724df
3
+ metadata.gz: bfdcab4e5984a23cebaa698fe65888d2e9133cac
4
+ data.tar.gz: 11333c03404c2d9744abc14eb11f317d3d0dec96
5
5
  SHA512:
6
- metadata.gz: 2eb3bf2e9da5dbe0975ed317db74a7d8fff91ee8ab38b740e5c7abf566b35ba8dba5f45d661cf38739e3e2ea53e8cb16d06c344cb0988172a61f8f10b1969229
7
- data.tar.gz: 936c026784cc3a57687cf97b2b5b233c31a66854f60f746eabf6fd8268efc9f3e741016a50ee360fd42a1c66e59b4a8049154af2e5c43b37e249a55638297c74
6
+ metadata.gz: 4acccb1b860384c10200da8c5c38da8f21700a6d7245866971de24d40be9aaf27c9ebfcc8d0fd863d51ad5d980e0d24a490c6cbd5b337d1b876e4da4ed012593
7
+ data.tar.gz: ed378bf13882af17043aec5f78ee22fa314802a9629a082d19b3fb7a1f7f00f8a0b60231c09c7768f30b2c80972f49029b234025f21928dfb96434df290ddf4f
@@ -1,7 +1,7 @@
1
1
  require 'model/active_record_model'
2
2
 
3
3
  module Regressor
4
- class ModelGenerator < Rails::Generators::Base
4
+ class ModelGenerator < ::Rails::Generators::Base
5
5
  source_root(File.expand_path(File.dirname(__FILE__)))
6
6
 
7
7
  def create_regression_files
@@ -0,0 +1,25 @@
1
+ module Regressor
2
+ module Model
3
+ class Expression
4
+
5
+ attr_accessor :subject, :expectation, :matcher, :matcher_expectation, :modification
6
+
7
+ def initialize(subject, expectation, matcher, matcher_expectation, modification = nil)
8
+ self.subject = subject
9
+ self.expectation = expectation
10
+ self.matcher = matcher
11
+ self.matcher_expectation = matcher_expectation
12
+ self.modification = modification
13
+ end
14
+
15
+ def to_s
16
+ if self.modification.nil?
17
+ "it { #{self.subject}.#{self.expectation} #{self.matcher}(:#{self.matcher_expectation}) }"
18
+ else
19
+ "it { #{self.subject}.#{self.expectation} #{self.matcher}(:#{self.matcher_expectation}).#{self.modification} }"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -3,10 +3,19 @@ module Regressor
3
3
  module Mongoid
4
4
  module Database
5
5
  module Field
6
+
7
+ def fields_as_string
8
+ fields.join("\n ")
9
+ end
10
+
6
11
  def fields
7
12
  @model.fields.keys.map do |field|
8
- "it { is_expected.to have_field(:#{field}).of_type(#{field_type(@model, field)}) }"
9
- end.join("\n ")
13
+ ::Regressor::Model::Expression.new(:is_expected,
14
+ :to,
15
+ :have_field,
16
+ field,
17
+ "of_type(#{field_type(@model, field)})").to_s
18
+ end
10
19
  end
11
20
 
12
21
  private
@@ -3,11 +3,19 @@ module Regressor
3
3
  module Mongoid
4
4
  module Relation
5
5
  module BelongsTo
6
+
7
+ def belongs_to_relations_as_string
8
+ belongs_to_relations.join("\n ")
9
+ end
10
+
6
11
  def belongs_to_relations
7
12
  @model.reflect_on_all_associations(:belongs_to).map(&:name).map do |relation|
8
- "it { is_expected.to belong_to :#{relation} }"
9
- end.join("\n ")
13
+ ::Regressor::Model::Expression.new(:is_expected,
14
+ :to,
15
+ :belong_to, relation).to_s
16
+ end
10
17
  end
18
+
11
19
  end
12
20
  end
13
21
  end
@@ -3,11 +3,18 @@ module Regressor
3
3
  module Mongoid
4
4
  module Relation
5
5
  module Embedded
6
+
7
+ def embedded_relations_as_string
8
+ embedded_relations.join("\n ")
9
+ end
10
+
6
11
  def embedded_relations
7
12
  @model.embedded_relations.keys.map do |key|
8
13
  macro = @model.embedded_relations[key].macro
9
- "it { is_expected.to #{embedded_type[macro]} :#{key} }"
10
- end.join("\n ")
14
+ ::Regressor::Model::Expression.new(:is_expected,
15
+ :to,
16
+ embedded_type[macro], key).to_s
17
+ end
11
18
  end
12
19
 
13
20
  private
@@ -3,11 +3,19 @@ module Regressor
3
3
  module Mongoid
4
4
  module Relation
5
5
  module HasMany
6
+
7
+ def has_many_relations_as_string
8
+ has_many_relations.join("\n ")
9
+ end
10
+
6
11
  def has_many_relations
7
12
  @model.reflect_on_all_associations(:has_many).map(&:name).map do |relation|
8
- "it { is_expected.to have_many :#{relation} }"
9
- end.join("\n ")
13
+ ::Regressor::Model::Expression.new(:is_expected,
14
+ :to,
15
+ :have_many, relation).to_s
16
+ end
10
17
  end
18
+
11
19
  end
12
20
  end
13
21
  end
@@ -3,11 +3,19 @@ module Regressor
3
3
  module Mongoid
4
4
  module Relation
5
5
  module HasOne
6
+
7
+ def has_one_relations_as_string
8
+ has_one_relations.join("\n ")
9
+ end
10
+
6
11
  def has_one_relations
7
12
  @model.reflect_on_all_associations(:has_one).map(&:name).map do |relation|
8
- "it { is_expected.to have_one :#{relation} }"
9
- end.join("\n ")
13
+ ::Regressor::Model::Expression.new(:is_expected,
14
+ :to,
15
+ :have_one, relation).to_s
16
+ end
10
17
  end
18
+
11
19
  end
12
20
  end
13
21
  end
@@ -1,3 +1,4 @@
1
+ require 'model/expression'
1
2
  require 'model/mongoid/database/field'
2
3
  require 'model/mongoid/relation/has_many'
3
4
  require 'model/mongoid/relation/has_one'
@@ -1,3 +1,3 @@
1
1
  module Regressor
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
@@ -6,11 +6,11 @@ RSpec.describe <%= @model.model %>, regressor: true do
6
6
  <%= @model.version_include %>
7
7
 
8
8
  # === Relations ===
9
- <%= @model.belongs_to_relations %>
10
- <%= @model.has_one_relations %>
11
- <%= @model.has_many_relations %>
12
- <%= @model.embedded_relations %>
9
+ <%= @model.belongs_to_relations_as_string %>
10
+ <%= @model.has_one_relations_as_string %>
11
+ <%= @model.has_many_relations_as_string %>
12
+ <%= @model.embedded_relations_as_string %>
13
13
 
14
14
  # === Database (Fields) ===
15
- <%= @model.fields %>
15
+ <%= @model.fields_as_string %>
16
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens
@@ -92,6 +92,34 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec-rails
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.3'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '3.3'
109
+ - !ruby/object:Gem::Dependency
110
+ name: mongoid
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 4.0.0
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 4.0.0
95
123
  description: Regressor generates regression specs based on ActiveRecord models. Currently
96
124
  relations, validations, attributes, and database indexes are supported.
97
125
  email:
@@ -124,6 +152,7 @@ files:
124
152
  - lib/model/active_record/validation/numericality.rb
125
153
  - lib/model/active_record/validation/presence.rb
126
154
  - lib/model/active_record_model.rb
155
+ - lib/model/expression.rb
127
156
  - lib/model/mongoid/database/field.rb
128
157
  - lib/model/mongoid/document/timestamp.rb
129
158
  - lib/model/mongoid/document/version.rb