incr 0.7.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Incr::Command::Laravel do
4
+ let(:args) do
5
+ ['major']
6
+ end
7
+
8
+ describe '#execute' do
9
+ context 'with version specified in config/app.php' do
10
+ before(:each) do
11
+ @tmpdir = Dir.mktmpdir('incr', '.')
12
+ Dir.mkdir(File.join(@tmpdir, "config"))
13
+ end
14
+
15
+ let(:global_options) do
16
+ {
17
+ commit: false,
18
+ tag: false,
19
+ noop: true,
20
+ version_file_dir: @tmpdir,
21
+ tag_name_pattern: 'v%s'
22
+ }
23
+ end
24
+
25
+ let(:app_config_filename) { "#{File.dirname(__FILE__)}/../../fixtures/laravel/app.php" }
26
+
27
+ it 'should increase the version number' do
28
+ copy_files(File.join(@tmpdir, "config"), app_config_filename)
29
+
30
+ expected = %(<?php
31
+
32
+ return [
33
+ 'name' => env('APP_NAME', 'Laravel'),
34
+ 'version' => '2.0.0',
35
+ ]
36
+ )
37
+
38
+ command = Incr::Command::Laravel.new(args, global_options)
39
+ expect{ command.execute() }.to output("v2.0.0\n").to_stdout
40
+
41
+ result = read_file(File.join(@tmpdir, 'config', 'app.php'))
42
+ expect(result).to eql(expected)
43
+ end
44
+
45
+ after(:each) do
46
+ FileUtils.remove_entry_secure(@tmpdir)
47
+ end
48
+ end
49
+
50
+ context 'without expected files' do
51
+ before(:each) do
52
+ @tmpdir = Dir.mktmpdir('incr', '.')
53
+ end
54
+
55
+ let(:global_options) do
56
+ {
57
+ commit: false,
58
+ tag: false,
59
+ noop: true,
60
+ version_file_dir: @tmpdir,
61
+ tag_name_pattern: 'v%s'
62
+ }
63
+ end
64
+
65
+ it 'should return an error' do
66
+ command = Incr::Command::Laravel.new(args, global_options)
67
+ expected = "'#{File.join('.', @tmpdir, 'config', 'app.php')}': file not found.\n"
68
+ expect { command.execute() }.to output(expected).to_stderr
69
+ end
70
+
71
+ after(:each) do
72
+ FileUtils.remove_entry_secure(@tmpdir)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe Incr::Command::Mix do
4
+ let(:args) do
5
+ ['major']
6
+ end
7
+
8
+ describe '#execute' do
9
+ context 'with a normal mix file' do
10
+ before(:each) do
11
+ @tmpdir = Dir.mktmpdir('incr', '.')
12
+ end
13
+
14
+ let(:global_options) do
15
+ {
16
+ commit: false,
17
+ tag: false,
18
+ noop: true,
19
+ version_file_dir: @tmpdir,
20
+ tag_name_pattern: 'v%s'
21
+ }
22
+ end
23
+
24
+ let(:mix_filename) { "#{File.dirname(__FILE__)}/../../fixtures/mix/mix.exs" }
25
+ it 'should increase the version number' do
26
+ copy_files(@tmpdir, mix_filename)
27
+
28
+ expected = %+defmodule Foobar.MixProject do
29
+ use Mix.Project
30
+
31
+ @version "2.0.0"
32
+
33
+ def project do
34
+ [
35
+ app: :foobar,
36
+ version: @version,
37
+ elixir: "~> 1.13",
38
+ start_permanent: Mix.env() == :prod,
39
+ deps: deps()
40
+ ]
41
+ end
42
+
43
+ # Run "mix help compile.app" to learn about applications.
44
+ def application do
45
+ [
46
+ extra_applications: [:logger]
47
+ ]
48
+ end
49
+
50
+ # Run "mix help deps" to learn about dependencies.
51
+ defp deps do
52
+ [
53
+ # {:dep_from_hexpm, "~> 0.3.0"},
54
+ # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
55
+ ]
56
+ end
57
+ end
58
+ +
59
+ mix = Incr::Command::Mix.new(args, global_options)
60
+ expect{ mix.execute() }.to output("v2.0.0\n").to_stdout
61
+
62
+ result = read_file(File.join(@tmpdir, 'mix.exs'))
63
+ expect(result).to eql(expected)
64
+ end
65
+
66
+ after(:each) do
67
+ FileUtils.remove_entry_secure(@tmpdir)
68
+ end
69
+ end
70
+
71
+ context 'without expected files' do
72
+ before(:each) do
73
+ @tmpdir = Dir.mktmpdir('incr', '.')
74
+ end
75
+
76
+ let(:global_options) do
77
+ {
78
+ commit: false,
79
+ tag: false,
80
+ noop: true,
81
+ version_file_dir: @tmpdir,
82
+ tag_name_pattern: 'v%s'
83
+ }
84
+ end
85
+
86
+ it 'should return an error' do
87
+ mix = Incr::Command::Mix.new(args, global_options)
88
+ expected = "'#{File.join('.', @tmpdir, 'mix.exs')}': file not found.\n"
89
+ expect { mix.execute() }.to output(expected).to_stderr
90
+ end
91
+
92
+ after(:each) do
93
+ FileUtils.remove_entry_secure(@tmpdir)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+
3
+ describe Incr::Command::Npm do
4
+ let(:args) do
5
+ ['major']
6
+ end
7
+
8
+ describe '#execute' do
9
+ context 'with NPM v6 files' do
10
+ before(:each) do
11
+ @tmpdir = Dir.mktmpdir('incr', '.')
12
+ end
13
+
14
+ let(:global_options) do
15
+ {
16
+ commit: false,
17
+ tag: false,
18
+ noop: true,
19
+ version_file_dir: @tmpdir,
20
+ tag_name_pattern: 'v%s'
21
+ }
22
+ end
23
+
24
+ let(:npmv6_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package.json" }
25
+ let(:npmv6_package_lock_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package-lock.json" }
26
+
27
+ it 'should increase the version number' do
28
+ copy_files(@tmpdir, npmv6_package_filename, npmv6_package_lock_filename)
29
+
30
+ expected = %({
31
+ "name": "foobar",
32
+ "version": "8.0.0",
33
+ "dependencies": {
34
+ "is-number": "^7.0.0"
35
+ }
36
+ }
37
+ )
38
+ lockfile_expected = %({
39
+ "name": "foobar",
40
+ "version": "8.0.0",
41
+ "lockfileVersion": 1,
42
+ "requires": true,
43
+ "dependencies": {
44
+ "is-number": {
45
+ "version": "7.0.0",
46
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
47
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
48
+ }
49
+ }
50
+ }
51
+ )
52
+ npm = Incr::Command::Npm.new(args, global_options)
53
+ expect{ npm.execute() }.to output("v8.0.0\n").to_stdout
54
+
55
+ result = read_file(File.join(@tmpdir, 'package.json'))
56
+ expect(result).to eql(expected)
57
+
58
+ lockfile_result = read_file(File.join(@tmpdir, 'package-lock.json'))
59
+ expect(lockfile_expected).to eql(lockfile_result)
60
+ end
61
+
62
+ after(:each) do
63
+ FileUtils.remove_entry_secure(@tmpdir)
64
+ end
65
+ end
66
+
67
+ context 'with NPM v7 files' do
68
+ before(:each) do
69
+ @tmpdir = Dir.mktmpdir('incr', '.')
70
+ end
71
+
72
+ let(:global_options) do
73
+ {
74
+ commit: false,
75
+ tag: false,
76
+ noop: true,
77
+ version_file_dir: @tmpdir,
78
+ tag_name_pattern: 'v%s'
79
+ }
80
+ end
81
+
82
+ let(:npmv7_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv7/package.json" }
83
+ let(:npmv7_package_lock_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv7/package-lock.json" }
84
+
85
+ it 'should increase the version number' do
86
+ copy_files(@tmpdir, npmv7_package_filename, npmv7_package_lock_filename)
87
+
88
+ expected = %({
89
+ "name": "foobar",
90
+ "version": "8.0.0",
91
+ "dependencies": {
92
+ "is-number": "^7.0.0"
93
+ }
94
+ }
95
+ )
96
+ lockfile_expected = %({
97
+ "name": "foobar",
98
+ "version": "8.0.0",
99
+ "lockfileVersion": 2,
100
+ "requires": true,
101
+ "packages": {
102
+ "": {
103
+ "name": "foobar",
104
+ "version": "8.0.0",
105
+ "dependencies": {
106
+ "is-number": "^7.0.0"
107
+ }
108
+ },
109
+ "node_modules/is-number": {
110
+ "version": "7.0.0",
111
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
112
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
113
+ "engines": {
114
+ "node": ">=0.12.0"
115
+ }
116
+ }
117
+ },
118
+ "dependencies": {
119
+ "is-number": {
120
+ "version": "7.0.0",
121
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
122
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
123
+ }
124
+ }
125
+ }
126
+ )
127
+ npm = Incr::Command::Npm.new(args, global_options)
128
+ expect{ npm.execute() }.to output("v8.0.0\n").to_stdout
129
+
130
+ result = read_file(File.join(@tmpdir, 'package.json'))
131
+ expect(result).to eql(expected)
132
+
133
+ lockfile_result = read_file(File.join(@tmpdir, 'package-lock.json'))
134
+ expect(lockfile_expected).to eql(lockfile_result)
135
+ end
136
+
137
+ after(:each) do
138
+ FileUtils.remove_entry_secure(@tmpdir)
139
+ end
140
+ end
141
+
142
+ context 'without expected files' do
143
+ before(:each) do
144
+ @tmpdir = Dir.mktmpdir('incr', '.')
145
+ end
146
+
147
+ let(:global_options) do
148
+ {
149
+ commit: false,
150
+ tag: false,
151
+ noop: true,
152
+ version_file_dir: @tmpdir,
153
+ tag_name_pattern: 'v%s'
154
+ }
155
+ end
156
+
157
+ it 'should return an error' do
158
+ npm = Incr::Command::Npm.new(args, global_options)
159
+ expected = "'#{File.join('.', @tmpdir, 'package.json')}': file not found.\n"
160
+ expect { npm.execute() }.to output(expected).to_stderr
161
+ end
162
+
163
+ after(:each) do
164
+ FileUtils.remove_entry_secure(@tmpdir)
165
+ end
166
+ end
167
+
168
+ context 'without expected lock file' do
169
+ before(:each) do
170
+ @tmpdir = Dir.mktmpdir('incr', '.')
171
+ end
172
+
173
+ let(:global_options) do
174
+ {
175
+ commit: false,
176
+ tag: false,
177
+ noop: true,
178
+ version_file_dir: @tmpdir,
179
+ tag_name_pattern: 'v%s'
180
+ }
181
+ end
182
+
183
+ let(:npmv6_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package.json" }
184
+
185
+ it 'should return an error ' do
186
+ copy_files(@tmpdir, npmv6_package_filename)
187
+ npm = Incr::Command::Npm.new(args, global_options)
188
+ expected = "'#{File.join('.', @tmpdir, 'package-lock.json')}': file not found.\n"
189
+ expect { npm.execute() }.to output(expected).to_stderr
190
+ end
191
+
192
+ after(:each) do
193
+ FileUtils.remove_entry_secure(@tmpdir)
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ SIMPLE_FILE_CONTENT = %(Hello, World!)
4
+
5
+ JSON_FILE_CONTENT = %({
6
+ "name": "incr",
7
+ "version": "7.0.0",
8
+ "dependencies": {
9
+ "is-number": "7.0.0"
10
+ }
11
+ })
12
+
13
+ describe Incr::Service::FileHelper do
14
+ describe '.replace' do
15
+ context 'with a simple text file' do
16
+ let(:filename) do
17
+ create_tempfile(SIMPLE_FILE_CONTENT)
18
+ end
19
+
20
+ it 'should replace specified regular expression' do
21
+ expected = "Buongiorno, World!"
22
+
23
+ Incr::Service::FileHelper.replace(filename, /^Hel{2}o/, 'Buongiorno')
24
+ result = read_file(filename)
25
+
26
+ expect(result).to eql(expected)
27
+ end
28
+ end
29
+
30
+ context 'with a JSON text file' do
31
+ let(:filename) do
32
+ create_tempfile(JSON_FILE_CONTENT)
33
+ end
34
+ end
35
+
36
+ context 'with a JSON file' do
37
+ let(:filename) do
38
+ create_tempfile(JSON_FILE_CONTENT)
39
+ end
40
+
41
+ it 'should replace specified regular expression, once' do
42
+ expected = %({
43
+ "name": "incr",
44
+ "version": "7.0.1",
45
+ "dependencies": {
46
+ "is-number": "7.0.0"
47
+ }
48
+ })
49
+
50
+ Incr::Service::FileHelper.replace(filename, /7.0.0/, '7.0.1')
51
+ result = read_file(filename)
52
+
53
+ expect(result).to eql(expected)
54
+ end
55
+ end
56
+
57
+ context 'with a non-existent text' do
58
+ let(:filename) do
59
+ create_tempfile(SIMPLE_FILE_CONTENT)
60
+ end
61
+
62
+ it 'should not do anything' do
63
+ expected = "Hello, World!"
64
+
65
+ Incr::Service::FileHelper.replace(filename, /7.0.0/, '7.0.1')
66
+ result = read_file(filename)
67
+
68
+ expect(result).to eql(expected)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ require 'sem_version'
4
+
5
+ describe Incr::Service::Version do
6
+ describe '.increment_segment' do
7
+ context 'with a SemVersion object' do
8
+ let(:version) { SemVersion.new('1.2.4') }
9
+
10
+ it 'should increment the major segment and reset the minor and patch segments' do
11
+ expected = '2.0.0'
12
+ result = Incr::Service::Version.increment_segment(version, 'major')
13
+
14
+ expect(result.to_s).to eql(expected)
15
+ end
16
+
17
+ it 'should increment the minor segment and reset the patch segment' do
18
+ expected = '1.3.0'
19
+ result = Incr::Service::Version.increment_segment(version, 'minor')
20
+
21
+ expect(result.to_s).to eql(expected)
22
+ end
23
+
24
+ it 'should increment the patch segment' do
25
+ expected = '1.2.5'
26
+ result = Incr::Service::Version.increment_segment(version, 'patch')
27
+
28
+ expect(result.to_s).to eql(expected)
29
+ end
30
+ end
31
+
32
+ context 'with a version string' do
33
+ let(:version) { '1.0.0' }
34
+
35
+ it 'should throw an error' do
36
+ expect {
37
+ Incr::Service::Version.increment_segment(version, 'patch')
38
+ }.to raise_error(NoMethodError)
39
+ end
40
+ end
41
+
42
+ context 'with an unknown segment' do
43
+ let(:version) { SemVersion.new('1.0.0') }
44
+
45
+ it 'should not do anything' do
46
+ expected = '1.0.0'
47
+ result = Incr::Service::Version.increment_segment(version, 'foobar')
48
+
49
+ expect(result.to_s).to eql(expected)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,122 @@
1
+ require 'incr'
2
+
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ def create_tempfile(content)
7
+ file = Tempfile.new('incr')
8
+ file << content
9
+ file.flush()
10
+ file.close()
11
+
12
+ file.path
13
+ end
14
+
15
+ def copy_files(dir, *filenames)
16
+ filenames.each do |filename|
17
+ FileUtils.cp(filename, dir)
18
+ end
19
+ end
20
+
21
+ def read_file(filename)
22
+ IO.read(filename)
23
+ end
24
+
25
+ # This file was generated by the `rspec --init` command. Conventionally, all
26
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
27
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
28
+ # this file to always be loaded, without a need to explicitly require it in any
29
+ # files.
30
+ #
31
+ # Given that it is always loaded, you are encouraged to keep this file as
32
+ # light-weight as possible. Requiring heavyweight dependencies from this file
33
+ # will add to the boot time of your test suite on EVERY test run, even for an
34
+ # individual file that may not need all of that loaded. Instead, consider making
35
+ # a separate helper file that requires the additional dependencies and performs
36
+ # the additional setup, and require it from the spec files that actually need
37
+ # it.
38
+ #
39
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
40
+ RSpec.configure do |config|
41
+ # rspec-expectations config goes here. You can use an alternate
42
+ # assertion/expectation library such as wrong or the stdlib/minitest
43
+ # assertions if you prefer.
44
+ config.expect_with :rspec do |expectations|
45
+ # This option will default to `true` in RSpec 4. It makes the `description`
46
+ # and `failure_message` of custom matchers include text for helper methods
47
+ # defined using `chain`, e.g.:
48
+ # be_bigger_than(2).and_smaller_than(4).description
49
+ # # => "be bigger than 2 and smaller than 4"
50
+ # ...rather than:
51
+ # # => "be bigger than 2"
52
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
53
+ end
54
+
55
+ # rspec-mocks config goes here. You can use an alternate test double
56
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
57
+ config.mock_with :rspec do |mocks|
58
+ # Prevents you from mocking or stubbing a method that does not exist on
59
+ # a real object. This is generally recommended, and will default to
60
+ # `true` in RSpec 4.
61
+ mocks.verify_partial_doubles = true
62
+ end
63
+
64
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
65
+ # have no way to turn it off -- the option exists only for backwards
66
+ # compatibility in RSpec 3). It causes shared context metadata to be
67
+ # inherited by the metadata hash of host groups and examples, rather than
68
+ # triggering implicit auto-inclusion in groups with matching metadata.
69
+ config.shared_context_metadata_behavior = :apply_to_host_groups
70
+
71
+ # The settings below are suggested to provide a good initial experience
72
+ # with RSpec, but feel free to customize to your heart's content.
73
+ =begin
74
+ # This allows you to limit a spec run to individual examples or groups
75
+ # you care about by tagging them with `:focus` metadata. When nothing
76
+ # is tagged with `:focus`, all examples get run. RSpec also provides
77
+ # aliases for `it`, `describe`, and `context` that include `:focus`
78
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
79
+ config.filter_run_when_matching :focus
80
+
81
+ # Allows RSpec to persist some state between runs in order to support
82
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
83
+ # you configure your source control system to ignore this file.
84
+ config.example_status_persistence_file_path = "spec/examples.txt"
85
+
86
+ # Limits the available syntax to the non-monkey patched syntax that is
87
+ # recommended. For more details, see:
88
+ # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
89
+ config.disable_monkey_patching!
90
+
91
+ # This setting enables warnings. It's recommended, but in some cases may
92
+ # be too noisy due to issues in dependencies.
93
+ config.warnings = true
94
+
95
+ # Many RSpec users commonly either run the entire suite or an individual
96
+ # file, and it's useful to allow more verbose output when running an
97
+ # individual spec file.
98
+ if config.files_to_run.one?
99
+ # Use the documentation formatter for detailed output,
100
+ # unless a formatter has already been configured
101
+ # (e.g. via a command-line flag).
102
+ config.default_formatter = "doc"
103
+ end
104
+
105
+ # Print the 10 slowest examples and example groups at the
106
+ # end of the spec run, to help surface which specs are running
107
+ # particularly slow.
108
+ config.profile_examples = 10
109
+
110
+ # Run specs in random order to surface order dependencies. If you find an
111
+ # order dependency and want to debug it, you can fix the order by providing
112
+ # the seed, which is printed after each run.
113
+ # --seed 1234
114
+ config.order = :random
115
+
116
+ # Seed global randomization in this process using the `--seed` CLI option.
117
+ # Setting this allows you to use `--seed` to deterministically reproduce
118
+ # test failures related to randomization by passing the same `--seed` value
119
+ # as the one that triggered the failure.
120
+ Kernel.srand config.seed
121
+ =end
122
+ end