qor_test 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ test/example_test.rb
18
+ tmp
19
+ config
20
+ QorTest*
data/.gitkeep ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qor_test.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jinzhu
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,39 @@
1
+ # QorTest
2
+
3
+ ## Usage
4
+
5
+ config/qor/test.rb
6
+
7
+ gem 'nokogiri', [{:git => "git://github.com/tenderlove/nokogiri.git", :branch => "1.4"}, {:git => "git://github.com/tenderlove/nokogiri.git"}]
8
+
9
+ gem 'nokogiri', :git => "git://github.com/tenderlove/nokogiri.git", :branch => "1.4"
10
+ gem 'nokogiri', :git => "git://github.com/tenderlove/nokogiri.git"
11
+ gem 'RedCloth', ">= 4.1.0", "< 4.2.0"
12
+
13
+ env 'default' do
14
+ ruby '1.9.3'
15
+ gem 'rails', ['3.1', '3.2', '4.0.0.beta']
16
+ end
17
+
18
+ env '1.8.7' do
19
+ ruby '1.8.7'
20
+ gem 'rails', ['3.1', '3.2']
21
+ end
22
+
23
+ test/test_helper.rb
24
+
25
+ load_dummy_rails_env #:models_path => [], :migrations_path => []
26
+
27
+
28
+ Run:
29
+
30
+ qor_test -e default -c 'ruby test/xxxx'
31
+ qor_test -e 1.8.7 -c 'rake test'
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'rubygems/package_task'
3
+ require 'rake/testtask'
4
+ require "bundler/gem_tasks"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task :default => :test
data/bin/qor_test ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require "pathname"
5
+ bin_file = Pathname.new(__FILE__).realpath
6
+ $:.unshift File.expand_path("../../lib", bin_file)
7
+
8
+ require "qor_test"
9
+
10
+ options = Qor::Test::CLI.option_parser
11
+ Qor::Test::CLI.new(options).run
@@ -0,0 +1,70 @@
1
+ module Qor
2
+ module Test
3
+ class Bundler
4
+ attr_accessor :options
5
+
6
+ def initialize options={}
7
+ self.options = options
8
+ end
9
+
10
+ def gems_set_from_config
11
+ gems = Qor::Test::Configuration.gems(options).inject({}) do |s, node|
12
+ s[node.name] ||= []
13
+ s[node.name].concat Qor::Test::Gem.parse(node)
14
+ s
15
+ end.values
16
+
17
+ gems.length > 0 ? gems[0].product(*gems[1..-1]) : []
18
+ end
19
+
20
+ def gems_hash_from_gemfile
21
+ Qor::Test::Gemfile.gems(options).inject({}) do |s, node|
22
+ s[node.name.to_s] = Qor::Test::Gem.parse(node)[0]
23
+ s
24
+ end
25
+ end
26
+
27
+ def gemspecs
28
+ [Qor::Test::Configuration.gemspecs(options), Qor::Test::Gemfile.gemspecs(options)].flatten.compact
29
+ end
30
+
31
+ def sources
32
+ [Qor::Test::Configuration.sources(options), Qor::Test::Gemfile.sources(options)].flatten.compact
33
+ end
34
+
35
+ def generate_gemfiles
36
+ gems_set = gems_set_from_config
37
+ gems_hash = gems_hash_from_gemfile
38
+ gems_name = gems_hash.keys
39
+ gemfile_length = [gems_set.length, 1].max
40
+
41
+ gemfile_dir = File.join(Qor::Test::CLI.temp_directory, "qor_test-tmp-#{Time.now.to_i}")
42
+ FileUtils.mkdir_p(gemfile_dir)
43
+
44
+ filenames = (0...gemfile_length).map do |t|
45
+ gems = []
46
+ gem_names = gems_set[t].map(&:name)
47
+ gem_names.concat(gems_name).uniq!
48
+
49
+ gem_names.map do |name|
50
+ gems << (gems_set[t].select {|g| g.name == name}[0] || gems_hash[name])
51
+ end
52
+
53
+ file = File.new(File.join(gemfile_dir, "Gemfile.#{t}"), "w+")
54
+ # Add sources
55
+ file << sources.map { |source| "source #{source.value.inspect}\n" }.uniq.join("")
56
+ # Add gemspec
57
+ file << gemspecs.map do |gemspec|
58
+ "gemspec #{gemspec.value.nil? ? '' : gemspec.value.inspect.gsub(/^\{|\}$/,'')}\n"
59
+ end.uniq.join("")
60
+ # Add gems
61
+ file << gems.map(&:to_s).join("\n")
62
+ file.close
63
+ file.path
64
+ end
65
+
66
+ filenames
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,92 @@
1
+ require "optparse"
2
+ require 'tempfile'
3
+ require "fileutils"
4
+
5
+ module Qor
6
+ module Test
7
+ class CLI
8
+ BUNDLER_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze
9
+ attr_accessor :options
10
+
11
+ def initialize(options={})
12
+ self.options = options
13
+ end
14
+
15
+ def run
16
+ gemfiles = Qor::Test::Bundler.new(options).generate_gemfiles
17
+
18
+ puts ">> Generated #{gemfiles.count} Gemfile\n\n"
19
+
20
+ gemfiles.map do |gemfile|
21
+ begin
22
+ new_gemfile = "QorTest_" + File.basename(gemfile)
23
+ FileUtils.cp(gemfile, new_gemfile)
24
+ with_clean_gemfile(new_gemfile) do
25
+ puts ">> BUNDLE_GEMFILE=#{gemfile}"
26
+ ["bundle update", "#{options[:command]}\n\n"].map do |command|
27
+ puts ">> #{command}"
28
+ system(command) unless options[:pretend]
29
+ end
30
+ end
31
+ ensure
32
+ FileUtils.rm(new_gemfile)
33
+ end
34
+ end
35
+ end
36
+
37
+ def with_clean_gemfile(gemfile)
38
+ original_env = {}
39
+ BUNDLER_ENV_VARS.each do |key|
40
+ original_env[key] = ENV[key]
41
+ ENV[key] = nil
42
+ end
43
+
44
+ ENV['BUNDLE_GEMFILE'] = gemfile
45
+ yield
46
+ ensure
47
+ original_env.each { |key, value| ENV[key] = value }
48
+ end
49
+
50
+ def self.option_parser
51
+ options = {}
52
+
53
+ OptionParser.new do |opts|
54
+ opts.on( '-e', '--env env', 'Test Env') do |env|
55
+ options[:env] = env
56
+ end
57
+
58
+ opts.on( '-c', '--command command', 'Command') do |command|
59
+ options[:command] = command
60
+ end
61
+
62
+ opts.on( '-C', '--clean', 'Clean old temp files') do
63
+ puts "Cleaning temp files..."
64
+ FileUtils.rm_rf(Dir[File.join(temp_directory, "qor_test-tmp-*")])
65
+ exit
66
+ end
67
+
68
+ opts.on( '-p', '--pretend', 'Skip run command, only generate Gemfiles') do
69
+ options[:pretend] = true
70
+ end
71
+
72
+ opts.on( '-h', '--help', 'Display this help') do
73
+ puts opts
74
+ exit
75
+ end
76
+
77
+ opts.on( '-v', '--version', 'Show version number') do |version|
78
+ puts "Version: #{Qor::Test::VERSION}"
79
+ exit
80
+ end
81
+ end.parse!
82
+
83
+ options
84
+ end
85
+
86
+ def self.temp_directory
87
+ tempfile = Tempfile.new('fake')
88
+ File.dirname(tempfile.path)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,80 @@
1
+ module Qor
2
+ module Test
3
+ module Configuration
4
+ include Qor::Dsl
5
+ default_configs ["config/qor/test.rb"]
6
+
7
+ node :source
8
+ node :ruby
9
+ node :gemspec
10
+ node :gem
11
+
12
+ node :env do
13
+ node :gem
14
+ node :ruby
15
+ end
16
+
17
+ def self.gems(options={})
18
+ deep_find(:gem) do |n|
19
+ n.parent.root? || ((n.parent.config_name == :env) && n.parent.name.to_s == (options[:env] || 'default'))
20
+ end
21
+ end
22
+
23
+ def self.gemspecs(options={})
24
+ deep_find(:gemspec) do |n|
25
+ n.parent.root? || ((n.parent.config_name == :env) && n.parent.name.to_s == (options[:env] || 'default'))
26
+ end
27
+ end
28
+
29
+ def self.sources(options={})
30
+ deep_find(:source) do |n|
31
+ n.parent.root? || ((n.parent.config_name == :env) && n.parent.name.to_s == (options[:env] || 'default'))
32
+ end
33
+ end
34
+ end
35
+
36
+ class Gemfile
37
+ include Qor::Dsl
38
+ default_configs [ENV['QOR_TEST_GEMFILE'], ENV['BUNDLE_GEMFILE'], 'Gemfile']
39
+
40
+ node :source
41
+ node :ruby
42
+ node :gemspec
43
+ node :gem
44
+
45
+ node :git do
46
+ node :gem
47
+ end
48
+
49
+ node :platforms do
50
+ node :gem
51
+ end
52
+
53
+ node :path do
54
+ node :gem
55
+ end
56
+
57
+ node :group do
58
+ node :gem
59
+ end
60
+
61
+ def self.gems(options={})
62
+ deep_find(:gem) do |n|
63
+ n.parent.root? || (n.parent.config_name != :group) || (n.parent.name.to_s == 'test')
64
+ end
65
+ end
66
+
67
+ def self.gemspecs(options={})
68
+ deep_find(:gemspec) do |n|
69
+ n.parent.root? || (n.parent.config_name != :group) || (n.parent.name.to_s == 'test')
70
+ end
71
+ end
72
+
73
+ def self.sources(options={})
74
+ deep_find(:source) do |n|
75
+ n.parent.root? || (n.parent.config_name != :group) || (n.parent.name.to_s == 'test')
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,40 @@
1
+ module Qor
2
+ module Test
3
+ class Gem
4
+ attr_accessor :name, :options, :gem_option
5
+
6
+ def initialize(node, gem_option=nil)
7
+ self.name = node.name.to_s
8
+ self.gem_option = gem_option
9
+
10
+ [:git, :path, :platforms].map do |x|
11
+ if node.parent.config_name.to_sym == x
12
+ self.options = {x => node.parent.value}.merge(node.parent.options)
13
+ end
14
+ end
15
+ end
16
+
17
+ def to_s
18
+ if gem_option.is_a?(Array) && gem_option.length > 0
19
+ %{gem "#{name}", #{gem_option.map(&:inspect).join(", ")}}
20
+ elsif !gem_option.nil? && !gem_option.is_a?(Array)
21
+ %{gem "#{name}", #{gem_option.inspect}}
22
+ elsif options.is_a?(Hash)
23
+ %{gem "#{name}", #{options.inspect}}
24
+ else
25
+ %{gem "#{name}"}
26
+ end
27
+ end
28
+
29
+ def self.parse(node)
30
+ if node.data.is_a?(Array) && node.data[0].is_a?(Array)
31
+ node.data.map do |gem_option|
32
+ gem_option.map {|x| Gem.new(node, x) }
33
+ end.flatten
34
+ else
35
+ Array(Gem.new(node, node.data))
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module Qor
2
+ module Test
3
+ class TestHelp
4
+
5
+ def self.load_dummy_rails_env(options={})
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Qor
2
+ module Test
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/qor_test.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'qor_dsl'
2
+ require 'qor_test/version'
3
+ require 'qor_test/bundler'
4
+ require 'qor_test/gem'
5
+ require 'qor_test/configuration'
6
+ require 'qor_test/test_help'
7
+ require 'qor_test/cli'
8
+
9
+ module Qor
10
+ module Test
11
+ end
12
+ end
data/qor_test.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "qor_test/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["Jinzhu"]
8
+ gem.email = ["wosmvp@gmail.com"]
9
+ gem.description = %q{Qor Test: Make test easier!}
10
+ gem.summary = %q{Qor Test: Make test easier!}
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "qor_test"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Qor::Test::VERSION
19
+
20
+ gem.add_dependency "qor_dsl"
21
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qor_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jinzhu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qor_dsl
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! 'Qor Test: Make test easier!'
31
+ email:
32
+ - wosmvp@gmail.com
33
+ executables:
34
+ - qor_test
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .gitkeep
40
+ - Gemfile
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - bin/qor_test
45
+ - lib/qor_test.rb
46
+ - lib/qor_test/bundler.rb
47
+ - lib/qor_test/cli.rb
48
+ - lib/qor_test/configuration.rb
49
+ - lib/qor_test/gem.rb
50
+ - lib/qor_test/test_help.rb
51
+ - lib/qor_test/version.rb
52
+ - qor_test.gemspec
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: ! 'Qor Test: Make test easier!'
77
+ test_files: []
78
+ has_rdoc: