gemika 0.1.0

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
+ SHA1:
3
+ metadata.gz: 7cbdbb33814a072effa330e193a8f0152dc19f59
4
+ data.tar.gz: cda2738ce94aa0b9d00308dc95d468f0200e49e7
5
+ SHA512:
6
+ metadata.gz: 37ce9d83de4e21f677727a56254bba582a286dab0bf50918404b59f3c2ef6fe437c01d42e5d5bf7bc810efac5ac90374cbcfaf9f479f73c7a0e88fdfeed91752
7
+ data.tar.gz: 5bf5915dcb1e2d72b3502fca16c3f55be8c4339ca6707c9e7c667f6f7d7564a4f43aa82ed9db67efeda3bdde182ee1b2ab5ca6ba9ef5e6068313e1b41003a5b6
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Henning Koch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # gemika
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'rake'
2
+ require 'bundler/gem_tasks'
data/gemika.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "gemika/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'gemika'
6
+ s.version = Gemika::VERSION
7
+ s.authors = ["Henning Koch"]
8
+ s.email = 'henning.koch@makandra.de'
9
+ s.homepage = 'https://github.com/makandra/gemika'
10
+ s.summary = 'Helpers for testing Ruby gems'
11
+ s.description = s.summary
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n").reject { |path| File.lstat(path).symlink? }
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").reject { |path| File.lstat(path).symlink? }
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,70 @@
1
+ require 'yaml'
2
+
3
+ module Gemika
4
+ class Database
5
+
6
+ def initialize(options = {})
7
+ config_folder = options.fetch(:config_folder, 'spec/support')
8
+ config_filename = travis? ? 'database.travis.yml' : 'database.yml'
9
+ config_path = File.join(config_folder, config_filename)
10
+ File.exists?(config_path) or raise ArgumentError, "Missing database configuration file: #{database_config_file}"
11
+ @config = YAML.load_file(config_path)
12
+ @connected = false
13
+ end
14
+
15
+ def connect
16
+ unless @connected
17
+ if pg?
18
+ adapter_config = (@config['postgresql'] || @config['postgres'] || @config['pg']).merge(adapter: 'postgresql')
19
+ elsif mysql2?
20
+ adapter_config = (@config['mysql2'] || @config['mysql']).merge(adapter: 'mysql2', encoding: 'utf8')
21
+ else
22
+ raise "Unknown database type"
23
+ end
24
+ ActiveRecord::Base.establish_connection(adapter_config)
25
+ @connected = true
26
+ end
27
+ end
28
+
29
+ def drop_tables!
30
+ connect
31
+ connection.tables.each do |table|
32
+ connection.drop_table table
33
+ end
34
+ end
35
+
36
+ def migrate(&block)
37
+ connect
38
+ ActiveRecord::Migration.class_eval(&block)
39
+ end
40
+
41
+ def rewrite_schema!(&block)
42
+ connect
43
+ drop_tables!
44
+ migrate(&block)
45
+ end
46
+
47
+ private
48
+
49
+ def connection
50
+ ActiveRecord::Base.connection
51
+ end
52
+
53
+ def pg?
54
+ not mysql2?
55
+ end
56
+
57
+ def mysql2?
58
+ gemfile_contents =~ /\bmysql2\b/
59
+ end
60
+
61
+ def travis?
62
+ !!ENV['TRAVIS']
63
+ end
64
+
65
+ def gemfile_contents
66
+ File.read(ENV['BUNDLE_GEMFILE'])
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,99 @@
1
+ require 'yaml'
2
+
3
+ module Gemika
4
+ class Matrix
5
+
6
+ COLOR_HEAD = "\e[44;97m"
7
+ COLOR_WARNING = "\e[33m"
8
+ COLOR_SUCCESS = "\e[32m"
9
+ COLOR_FAILURE = "\e[31m"
10
+ COLOR_RESET = "\e[0m"
11
+
12
+ def initialize(options)
13
+ @rows = options.fetch(:rows)
14
+ @results = {}
15
+ @all_passed = nil
16
+ end
17
+
18
+ def each(&block)
19
+ @all_passed = true
20
+ rows.each do |entry|
21
+ gemfile = entry['gemfile']
22
+ if compatible?(entry)
23
+ print_title gemfile
24
+ ENV['BUNDLE_GEMFILE'] = gemfile
25
+ gemfile_passed = block.call
26
+ @all_passed &= gemfile_passed
27
+ if gemfile_passed
28
+ @results[entry] = tint('Success', COLOR_SUCCESS)
29
+ else
30
+ @results[entry] = tint('Failed', COLOR_FAILURE)
31
+ end
32
+ else
33
+ @results[entry] = tint("Skipped", COLOR_WARNING)
34
+ end
35
+ end
36
+ print_summary
37
+ end
38
+
39
+ def self.from_travis_yml
40
+ travis_yml = YAML.load_file('.travis.yml')
41
+ rubies = travis_yml.fetch('rvm')
42
+ gemfiles = travis_yml.fetch('gemfile')
43
+ matrix_options = travis_yml.fetch('matrix', {})
44
+ excludes = matrix_options.fetch('exclude', [])
45
+ includes = matrix_options.fetch('include', [])
46
+ rows = []
47
+ rubies.each do |ruby|
48
+ gemfiles.each do |gemfile|
49
+ entry = { 'rvm' => ruby, 'gemfile' => gemfile }
50
+ rows << entry unless excludes.include?(entry)
51
+ end
52
+ end
53
+ rows += includes
54
+ new(:rows => rows)
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :rows
60
+
61
+ def compatible?(entry)
62
+ entry['rvm'] == RUBY_VERSION
63
+ end
64
+
65
+ def tint(message, color)
66
+ color + message + COLOR_RESET
67
+ end
68
+
69
+ def print_title(title)
70
+ puts
71
+ puts tint(title, COLOR_HEAD)
72
+ puts
73
+ end
74
+
75
+ def print_summary
76
+ print_title 'Summary'
77
+
78
+ gemfile_size = @results.keys.map { |entry| entry['gemfile'].size }.max
79
+ ruby_size = @results.keys.map { |entry| entry['rvm'].size }.max
80
+
81
+ @results.each do |entry, result|
82
+ puts "- #{entry['gemfile'].ljust(gemfile_size)} Ruby #{entry['rvm'].ljust(ruby_size)} #{result}"
83
+ end
84
+
85
+ puts
86
+
87
+ if @all_passed
88
+ puts tint("All gemfiles succeeded for Ruby #{RUBY_VERSION}.", COLOR_SUCCESS)
89
+ puts
90
+ else
91
+ puts tint('Some gemfiles failed.', COLOR_FAILURE)
92
+ puts
93
+ fail
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,26 @@
1
+ require 'gemika/matrix'
2
+
3
+ namespace :matrix do
4
+
5
+ desc "Run specs for all Ruby #{RUBY_VERSION} gemfiles"
6
+ task :spec do
7
+ Gemika::Matrix.from_travis_yml.each do
8
+ system("bundle exec rspec spec")
9
+ end
10
+ end
11
+
12
+ desc "Install all Ruby #{RUBY_VERSION} gemfiles"
13
+ task :install do
14
+ Gemika::Matrix.from_travis_yml.each do
15
+ system('bundle install')
16
+ end
17
+ end
18
+
19
+ desc "Update all Ruby #{RUBY_VERSION} gemfiles"
20
+ task :update do
21
+ Gemika::Matrix.from_travis_yml.each do
22
+ system('bundle update')
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ module Gemika
2
+ class RSpec
3
+ class << self
4
+
5
+ def configure_transactional_examples
6
+ ::RSpec.configure do |config|
7
+ config.around do |example|
8
+ if example.metadata.fetch(:transaction, example.metadata.fetch(:rollback, true))
9
+ ActiveRecord::Base.transaction do
10
+ begin
11
+ example.run
12
+ ensure
13
+ raise ActiveRecord::Rollback
14
+ end
15
+ end
16
+ else
17
+ example.run
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Gemika
2
+ VERSION = '0.1.0'
3
+ end
data/lib/gemika.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'gemika/version'
2
+ require 'gemika/database' if defined?(ActiveRecord)
3
+ require 'gemika/matrix'
4
+ require 'gemika/rspec' if defined?(RSpec)
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemika
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henning Koch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Helpers for testing Ruby gems
14
+ email: henning.koch@makandra.de
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - gemika.gemspec
24
+ - lib/gemika.rb
25
+ - lib/gemika/database.rb
26
+ - lib/gemika/matrix.rb
27
+ - lib/gemika/matrix_tasks.rb
28
+ - lib/gemika/rspec.rb
29
+ - lib/gemika/version.rb
30
+ homepage: https://github.com/makandra/gemika
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.6.6
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Helpers for testing Ruby gems
54
+ test_files: []