rspec_create_model 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 342535e338b1786e3675ed7b49f476c7dbf178705ed890c20e061c5e24488f7a
4
+ data.tar.gz: f21ca8a2e2a69cfbfaf0bf085504d2bc56554ec22ed9cef89840f71a1d230896
5
+ SHA512:
6
+ metadata.gz: 1502395a4641429d3a5478d9e6c3a3e5bb5f3d3c1c53cbe7d289f61988564cf0b661162f0a3be97a02d21a5e1b41982d800750992194b8ff09d547985f0c5b17
7
+ data.tar.gz: 48816672e69dc0f92e662c45b18de7a77e77547e1631eb99a39618de5c3e61e3a47e83f6b3b800dd2a6aeb7642ef981fdbb59a8bbf62ac882b8a3825a1e4125e
@@ -0,0 +1,44 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ tags: [ '*' ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ environment: production
12
+ permissions:
13
+ contents: read
14
+ packages: write
15
+
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Set up Ruby 3.0
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ ruby-version: 3.0.x
22
+
23
+ - name: Publish to GPR
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
33
+ OWNER: ${{ github.repository_owner }}
34
+
35
+ - name: Publish to RubyGems
36
+ run: |
37
+ mkdir -p $HOME/.gem
38
+ touch $HOME/.gem/credentials
39
+ chmod 0600 $HOME/.gem/credentials
40
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
+ gem build *.gemspec
42
+ gem push *.gem
43
+ env:
44
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,18 @@
1
+ name: Tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest, macos-latest]
9
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
+ ruby: [2.7, '3.0', 3.1, head, truffleruby, truffleruby-head]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
18
+ - run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rspec_match_structure.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
13
+
14
+ gem "simplecov"
15
+
16
+ gem "activerecord", "~> 7.0", ">= 7.0.3"
17
+ gem 'sqlite3'
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspec_create_model (0.0.1)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.0.3)
11
+ activesupport (= 7.0.3)
12
+ activerecord (7.0.3)
13
+ activemodel (= 7.0.3)
14
+ activesupport (= 7.0.3)
15
+ activesupport (7.0.3)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
21
+ concurrent-ruby (1.1.10)
22
+ diff-lcs (1.4.4)
23
+ docile (1.4.0)
24
+ i18n (1.10.0)
25
+ concurrent-ruby (~> 1.0)
26
+ minitest (5.16.0)
27
+ parallel (1.21.0)
28
+ parser (3.0.2.0)
29
+ ast (~> 2.4.1)
30
+ rainbow (3.0.0)
31
+ rake (13.0.6)
32
+ regexp_parser (2.1.1)
33
+ rexml (3.2.5)
34
+ rspec (3.10.0)
35
+ rspec-core (~> 3.10.0)
36
+ rspec-expectations (~> 3.10.0)
37
+ rspec-mocks (~> 3.10.0)
38
+ rspec-core (3.10.1)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-expectations (3.10.1)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-mocks (3.10.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-support (3.10.3)
47
+ rubocop (1.23.0)
48
+ parallel (~> 1.10)
49
+ parser (>= 3.0.0.0)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8, < 3.0)
52
+ rexml
53
+ rubocop-ast (>= 1.12.0, < 2.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 3.0)
56
+ rubocop-ast (1.13.0)
57
+ parser (>= 3.0.1.1)
58
+ ruby-progressbar (1.11.0)
59
+ simplecov (0.21.2)
60
+ docile (~> 1.1)
61
+ simplecov-html (~> 0.11)
62
+ simplecov_json_formatter (~> 0.1)
63
+ simplecov-html (0.12.3)
64
+ simplecov_json_formatter (0.1.3)
65
+ sqlite3 (1.4.4)
66
+ tzinfo (2.0.4)
67
+ concurrent-ruby (~> 1.0)
68
+ unicode-display_width (2.1.0)
69
+
70
+ PLATFORMS
71
+ x86_64-darwin-19
72
+ x86_64-darwin-20
73
+ x86_64-linux
74
+
75
+ DEPENDENCIES
76
+ activerecord (~> 7.0, >= 7.0.3)
77
+ rake (~> 13.0)
78
+ rspec (~> 3.0)
79
+ rspec_create_model!
80
+ rubocop (~> 1.7)
81
+ simplecov
82
+ sqlite3
83
+
84
+ BUNDLED WITH
85
+ 2.2.15
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ ![Tests](https://github.com/monade/rspec_create_model/actions/workflows/test.yml/badge.svg)
2
+ [![Gem Version](https://badge.fury.io/rb/rspec_create_model.svg)](https://badge.fury.io/rb/rspec_create_model)
3
+
4
+ # rspec_create_model
5
+
6
+ A rspec matcher for Rail's ActiveRecord, to check the type of models created from actions.
7
+
8
+ ## Installation
9
+
10
+ Add the gem to your Gemfile
11
+
12
+ ```ruby
13
+ gem 'rspec_create_model', github: 'monade/rspec_create_model'
14
+ ```
15
+
16
+ ## Example usage
17
+
18
+ Given the following records:
19
+
20
+ ```ruby
21
+ class Author < ActiveRecord::Base
22
+ attribute :name, type: :String
23
+ has_many :articles, dependent: :destroy
24
+
25
+ after_create :create_empty_book
26
+
27
+ def create_empty_book
28
+ Book.create!(author_id: id, title: "First Empty Book")
29
+ end
30
+ end
31
+
32
+ class Book < ActiveRecord::Base
33
+ belongs_to :author, optional: false
34
+ attribute :title, type: :String
35
+ end
36
+ ```
37
+
38
+ You can match created records like this:
39
+
40
+ ```ruby
41
+ expect { Author.create!(name: "Some author name") }.to create_model(Author)
42
+
43
+ expect { Author.create!(name: "Some author name") }
44
+ .to create_model(Author)
45
+ .and create_model(Book)
46
+ ```
47
+
48
+ When the matcher is called, 2 instace variable get set: **@created_record** and **@created_records**
49
+
50
+ these variables includes the newly created records. You can also use them if you want, like this:
51
+
52
+ ```ruby
53
+ expect { Author.create!(name: "Some author name") }.to create_model(Author)
54
+
55
+ expect(@created_record).to be_a(Author)
56
+ expect(@created_records).to all(be_a(Author))
57
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RspecCreateModel
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Matchers.define :create_model do |model_class|
4
+ match(notify_expectation_failures: true) do |block|
5
+ previous_elements = model_class.all.to_a
6
+ block.call
7
+ new_elements = model_class.all.to_a
8
+ created_elements = new_elements - previous_elements
9
+ if created_elements.any?
10
+ block.binding.receiver.instance_variable_set(:@created_record, created_elements.first)
11
+ block.binding.receiver.instance_variable_set(:@created_records, created_elements)
12
+ true
13
+ else
14
+ false
15
+ end
16
+ end
17
+
18
+ supports_block_expectations
19
+
20
+ failure_message do |_|
21
+ "Expected { } to create a new #{model_class}, but it didn't."
22
+ end
23
+
24
+ failure_message_when_negated do |_|
25
+ "Expected { } not to create a new #{model_class}, but it did."
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
4
+
5
+ require_relative "lib/rspec_create_model/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "rspec_create_model"
9
+ spec.version = RspecCreateModel::VERSION
10
+ spec.authors = ["Mònade"]
11
+ spec.email = ["hello@monade.io"]
12
+
13
+ spec.summary = "An RSpec matcher to match the structure of a given created model."
14
+ spec.description = "An RSpec matcher to match the structure of a given created model."
15
+ spec.homepage = "https://github.com/monade/rspec_create_model"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.5"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "https://github.com/monade/rspec_create_model/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency "activesupport"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_create_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mònade
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: An RSpec matcher to match the structure of a given created model.
28
+ email:
29
+ - hello@monade.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/gem-push.yml"
35
+ - ".github/workflows/test.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - README.md
42
+ - Rakefile
43
+ - lib/rspec_create_model.rb
44
+ - lib/rspec_create_model/version.rb
45
+ - rspec_create_model.gemspec
46
+ homepage: https://github.com/monade/rspec_create_model
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://github.com/monade/rspec_create_model
51
+ source_code_uri: https://github.com/monade/rspec_create_model
52
+ changelog_uri: https://github.com/monade/rspec_create_model/CHANGELOG.md
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.2.33
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: An RSpec matcher to match the structure of a given created model.
72
+ test_files: []