corundum 0.0.1 → 0.0.2

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.
@@ -6,19 +6,14 @@ module Corundum
6
6
  :gemspec_sanity
7
7
  end
8
8
 
9
- def receive_tasklibs(toolkit)
10
- @toolkit = toolkit
11
- end
12
-
13
- def default_configuration(namespace, toolkit_config)
14
- @configuration.namespace = namespace
15
- @configuration.gemspec = toolkit_config.gemspec
9
+ def default_configuration(toolkit)
10
+ setting(:gemspec, toolkit.gemspec)
16
11
  end
17
12
 
18
13
  def define
19
14
  in_namespace do
20
15
  task :files_exist do
21
- missing = @configuration.gemspec.files.find_all do |path|
16
+ missing = gemspec.files.find_all do |path|
22
17
  not File::exists?(path)
23
18
  end
24
19
 
@@ -7,36 +7,35 @@ module Corundum
7
7
  #collaboration of those two.
8
8
  #
9
9
  class RSpec < TaskLib
10
- def receive_tasklibs(toolkit)
11
- @toolkit = toolkit
10
+ def default_namespace
11
+ :rspec
12
12
  end
13
13
 
14
- def default_configuration(namespace, toolkit_config)
15
- @configuration.task_options = OpenStruct.new(
16
- :pattern => nil,
14
+ def default_configuration(toolkit)
15
+ setting(:task_options, nested(
16
+ :pattern => './spec{,/*/**}/*_spec.rb',
17
17
  :ruby_opts => nil,
18
+ :rspec_configs => nil,
18
19
  :rspec_opts => nil,
19
20
  :warning => false,
20
21
  :verbose => true,
21
22
  :fail_on_error => true,
22
23
  :ruby_opts => [],
24
+ :rspec_path => 'rspec',
23
25
  :rspec_opts => %w{--format documentation --out last_run --color --format documentation},
24
26
  :failure_message => "Spec examples failed.",
25
- :files_to_run => nil
26
- )
27
+ :files_to_run => "spec"
28
+ ))
27
29
 
28
- @configuration.namespace = namespace || :rspec
29
- @configuration.gemspec_path = toolkit_config.gemspec_path
30
- @configuration.qa_finished_path = toolkit_config.qa_finished_path
30
+ setting(:gemspec_path, toolkit.gemspec_path)
31
+ setting(:qa_finished_path, toolkit.finished_files.qa)
31
32
  end
32
33
 
33
34
  def resolve_configuration
34
- @configuration.task_options.rspec_configs = @configuration.task_options.rspec_opts
35
- @configuration.task_options.rspec_opts = []
36
- @configuration.task_options.rspec_path ||= 'rspec'
37
- @configuration.task_options.rspec_path = %x"which #{@configuration.task_options.rspec_path}".chomp
38
- @configuration.task_options.pattern ||= './spec{,/*/**}/*_spec.rb'
39
- @configuration.task_options.files_to_run ||= "spec"
35
+ #XXX Que?
36
+ @task_options.rspec_configs = task_options.rspec_opts
37
+ @task_options.rspec_opts = []
38
+ @task_options.rspec_path = %x"which #{task_options.rspec_path}".chomp
40
39
  end
41
40
 
42
41
  #XXX some point in the future, there needs to be a composible command
@@ -45,7 +44,7 @@ module Corundum
45
44
  cmd_parts = []
46
45
  cmd_parts << RUBY
47
46
  cmd_parts << options.ruby_opts
48
- cmd_parts << "-w" if options.warning?
47
+ cmd_parts << "-w" if options.warning
49
48
  if /^1\.8/ =~ RUBY_VERSION
50
49
  cmd_parts << "-S"
51
50
  end
@@ -66,7 +65,7 @@ module Corundum
66
65
  end
67
66
 
68
67
  def custom_options
69
- options = @configuration.task_options.dup
68
+ options = task_options.dup
70
69
  yield(options)
71
70
  return options
72
71
  end
@@ -75,7 +74,7 @@ module Corundum
75
74
  options = if block_given?
76
75
  custom_options{|options| yield(options) if block_given?}
77
76
  else
78
- @configuration.task_options
77
+ task_options
79
78
  end
80
79
  task name do
81
80
  RakeFileUtils.send(:verbose, verbose) do
@@ -86,7 +85,8 @@ module Corundum
86
85
  cmd = full_command(options)
87
86
  puts cmd if options.verbose
88
87
  success = system(cmd)
89
- rescue
88
+ rescue Object => ex
89
+ p ex
90
90
  puts options.failure_message if options.failure_message
91
91
  end
92
92
  raise("ruby #{cmd} failed") if options.fail_on_error unless success
@@ -96,9 +96,6 @@ module Corundum
96
96
  end
97
97
 
98
98
  def define
99
- desc "Run failing examples if any exist, otherwise, run the whole suite"
100
- task @configuration.namespace => "#{@configuration.namespace}:quick"
101
-
102
99
  in_namespace do
103
100
  desc "Always run every spec"
104
101
  define_spec_task(:all)
@@ -129,6 +126,9 @@ module Corundum
129
126
  end
130
127
  end
131
128
 
129
+ desc "Run failing examples if any exist, otherwise, run the whole suite"
130
+ task root_task => in_namespace(:quick)
131
+
132
132
  task :qa => in_namespace(:doc)
133
133
  end
134
134
  end
@@ -7,32 +7,21 @@ require 'corundum/tasklib'
7
7
  module Corundum
8
8
  class Publishing < TaskLib
9
9
  def default_namespace
10
- :email
10
+ :rubyforge
11
11
  end
12
12
 
13
- def receive_tasklibs(toolkit)
14
- @toolkit = toolkit
13
+ def default_configuration(toolkit)
14
+ setting(:ns, ns)
15
+ setting(:rubyforge, nested(:package_id => nil, :group_id => nil, :release_name => nil))
16
+ setting(:package_dir, nil)
17
+ setting(:gemspec, nil)
15
18
  end
16
19
 
17
- def default_configuration(namespace, toolkit_config)
18
- end
19
-
20
- def initialize(ns = :publish)
21
- @ns = ns
22
- @rubyforge = OpenStruct.new(:package_id => nil, :group_id => nil, :release_name => nil)
23
- @package_dir = nil
24
- @gemspec = nil
25
- yield self if block_given?
26
- define
27
- end
28
-
29
- attr_accessor :ns, :rubyforge, :package_dir, :gemspec
30
-
31
20
  def define
32
21
  desc "Publish the gem and its documentation to Rubyforge and Gemcutter"
33
- task @ns => ["#{@ns.to_s}:docs", "#{@ns.to_s}:rubyforge"]
22
+ task root_task => in_namespace(:docs, :rubyforge)
34
23
 
35
- namespace @ns do
24
+ in_namespace do
36
25
  desc 'Publish RDoc to RubyForge'
37
26
  task :docs do
38
27
  config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
@@ -70,26 +59,3 @@ module Corundum
70
59
  end
71
60
  end
72
61
  end
73
-
74
-
75
-
76
- module Corundum
77
- class Email < TaskLib
78
- def define
79
- desc 'Announce release on RubyForge and email'
80
- task @configuration.namespace => ["#{@configuration.namespace.to_s}:rubyforge", "#{@configuration.namespace.to_s}:email"]
81
- namespace @configuration.namespace do
82
- desc 'Post announcement to rubyforge.'
83
- task :rubyforge do
84
- require 'rubyforge'
85
- subject, title, body = announcement
86
-
87
- forge = RubyForge.new
88
- forge.configure
89
- forge.post_news(@configuration.rubyforge[:group_id], subject, "#{title}\n\n#{body}")
90
- puts "Posted to rubyforge"
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -6,49 +6,41 @@ module Corundum
6
6
  :coverage
7
7
  end
8
8
 
9
- def default_configuration(namespace, toolkit_config, testlib_config)
10
- @configuration.namespace = namespace
11
- @configuration.test_lib = nil
12
- @configuration.browser = toolkit_config.browser
13
- @configuration.report_dir = "doc/coverage"
14
- @configuration.report_path = nil
15
- @configuration.config_file = ".simplecov"
16
- @configuration.config_path = nil
17
- @configuration.filters = ["./spec"]
18
-
19
- @configuration.threshold = 80
20
- @configuration.files = OpenStruct.new(
21
- :code => toolkit_config.files.code
22
- )
23
- @configuration.groups = {}
24
-
25
- @configuration.all_files = toolkit_config.file_lists.code + toolkit_config.file_lists.test
9
+ def default_configuration(toolkit, testlib)
10
+ setting(:test_lib, testlib)
11
+ setting(:browser, toolkit.browser)
12
+ setting(:report_dir, "doc/coverage")
13
+ setting(:report_path, nil)
14
+ setting(:config_file, ".simplecov")
15
+ setting(:config_path, nil)
16
+ setting(:filters, ["./spec"])
17
+
18
+ setting(:threshold, 80)
19
+ setting(:groups, {})
20
+ setting(:code_files, toolkit.files.code)
21
+ setting(:all_files, toolkit.file_lists.code + toolkit.file_lists.test)
26
22
  end
27
23
 
28
24
  def resolve_configuration
29
- @configuration.config_path ||= File::expand_path(@configuration.config_file, Rake::original_dir)
30
- @configuration.report_path ||= File::join(@configuration.report_dir, "index.html")
31
- end
32
-
33
- def receive_tasklibs(toolkit, test_lib)
34
- @toolkit,@test_lib = toolkit, test_lib
25
+ @config_path ||= File::expand_path(config_file, Rake::original_dir)
26
+ @report_path ||= File::join(report_dir, "index.html")
35
27
  end
36
28
 
37
29
  def filters
38
- @configuration.filters.map do |pattern|
30
+ filters.map do |pattern|
39
31
  "add_filter \"#{pattern}\""
40
32
  end
41
33
  end
42
34
 
43
35
  def groups
44
- @configuration.groups.each_pair do |group, pattern|
36
+ groups.each_pair do |group, pattern|
45
37
  "add_group \"#{group}\", \"#{pattern}\""
46
38
  end
47
39
  end
48
40
 
49
41
  def config_file_contents
50
42
  contents = ["SimpleCov.start do"]
51
- contents << " coverage_dir \"#{@configuration.report_dir}\""
43
+ contents << " coverage_dir \"#{report_dir}\""
52
44
  contents += filters.map{|line| " " + line}
53
45
  contents += groups.map{|line| " " + line}
54
46
  contents << "end"
@@ -60,7 +52,7 @@ module Corundum
60
52
  file "Rakefile"
61
53
 
62
54
  task :example_config do
63
- $stderr.puts "Try this in #{@configuration.config_path}"
55
+ $stderr.puts "Try this in #{config_path}"
64
56
  $stderr.puts
65
57
  puts config_file_contents
66
58
  end
@@ -69,45 +61,45 @@ module Corundum
69
61
  File::exists?(File::join(Rake::original_dir, ".simplecov")) or fail "No .simplecov"
70
62
  end
71
63
 
72
- directory File::dirname(@configuration.report_path)
73
- file @configuration.report_path => @configuration.all_files do
64
+ directory File::dirname(report_path)
65
+ file report_path => all_files do
74
66
  options = @test_lib.custom_options do |options|
75
67
  options.rspec_opts += %w{-r simplecov}
76
68
  end
77
69
  sh @test_lib.full_command(options)
78
70
  end
79
71
 
80
- task :generate_report => [:preflight, @configuration.report_path]
72
+ task :generate_report => [:preflight, report_path]
81
73
 
82
74
  desc "View coverage in browser"
83
75
  task :view => :generate_report do
84
- sh "#{@configuration.browser} #{@configuration.report_path}"
76
+ sh "#{browser} #{report_path}"
85
77
  end
86
78
 
87
79
  task :verify_coverage => :generate_report do
88
80
  require 'nokogiri'
89
81
 
90
- doc = Nokogiri::parse(File::read(@configuration.report_path))
82
+ doc = Nokogiri::parse(File::read(report_path))
91
83
 
92
84
  coverage_total_xpath = "//span[@class='covered_percent']/span"
93
85
  percentage = doc.xpath(coverage_total_xpath).first.content.to_f
94
86
 
95
- raise "Coverage must be at least #{@configuration.threshold} but was #{percentage}" if percentage < @configuration.threshold
96
- puts "Coverage is #{percentage}% (required: #{@configuration.threshold}%)"
87
+ raise "Coverage must be at least #{threshold} but was #{percentage}" if percentage < threshold
88
+ puts "Coverage is #{percentage}% (required: #{threshold}%)"
97
89
  end
98
90
 
99
91
  task :find_stragglers => :generate_report do
100
92
  require 'nokogiri'
101
93
 
102
- doc = Nokogiri::parse(File::read(@configuration.report_path))
94
+ doc = Nokogiri::parse(File::read(report_path))
103
95
 
104
96
  covered_files = doc.xpath(
105
97
  "//table[@class='file_list']//td//a[@class='src_link']").map do |link|
106
98
  link.content
107
99
  end
108
100
 
109
- not_listed = covered_files - @configuration.files.code
110
- not_covered = @configuration.files.code - covered_files
101
+ not_listed = covered_files - @code_files
102
+ not_covered = @code_files - covered_files
111
103
  unless not_listed.empty? and not_covered.empty?
112
104
  raise ["Covered files and gemspec manifest don't match:",
113
105
  "Not in gemspec: #{not_listed.inspect}",
@@ -1,14 +1,12 @@
1
1
  require 'ostruct'
2
2
  require 'rake/tasklib'
3
+ require 'corundum/configurable'
3
4
 
4
5
  module Corundum
5
6
  class TaskLib < Rake::TaskLib
6
- attr_accessor :configuration
7
+ include Configurable
7
8
 
8
- def receive_tasklibs(*tasklibs)
9
- end
10
-
11
- def default_configuration(namespace, *tasklib_configs)
9
+ def default_configuration(*tasklibs)
12
10
  end
13
11
 
14
12
  def resolve_configuration
@@ -17,37 +15,39 @@ module Corundum
17
15
  def in_namespace(*tasknames)
18
16
  if tasknames.empty?
19
17
  if block_given?
20
- if @configuration.namespace.nil?
18
+ if @namespace_name.nil?
21
19
  yield
22
20
  else
23
- namespace @configuration.namespace do
21
+ namespace @namespace_name do
24
22
  yield
25
23
  end
26
24
  end
27
25
  end
28
26
  else
29
27
  tasknames.map do |taskname|
30
- [@configuration.namespace, taskname].compact.join(":")
28
+ [@namespace_name, taskname].compact.join(":")
31
29
  end
32
30
  end
33
31
  end
34
32
 
33
+ def root_task
34
+ @namespace_name || :default
35
+ end
36
+
35
37
  def default_namespace
36
38
  nil
37
39
  end
38
40
 
39
- def initialize(*tasklibs)
40
- @configuration = OpenStruct.new(:namespace => default_namespace)
41
-
42
- receive_tasklibs(*tasklibs)
41
+ def [](taskname)
42
+ in_namespace(taskname).first
43
+ end
43
44
 
44
- configs = tasklibs.map do |tl|
45
- tl.configuration
46
- end
47
- default_configuration(default_namespace, *configs)
45
+ def initialize(*tasklibs)
46
+ setting(:namespace_name, default_namespace)
48
47
 
48
+ default_configuration(*tasklibs)
49
49
 
50
- yield @configuration if block_given?
50
+ yield self if block_given?
51
51
 
52
52
  resolve_configuration
53
53
 
@@ -6,15 +6,10 @@ module Corundum
6
6
  :version_control
7
7
  end
8
8
 
9
- def receive_tasklibs(toolkit)
10
- @toolkit = toolkit
11
- end
12
-
13
- def default_configuration(namespace, toolkit_config)
14
- @configuration.namespace = namespace
15
- @configuration.gemspec = toolkit_config.gemspec
16
- @configuration.build_finished_file = toolkit_config.finished_files.build
17
- @configuration.tag = toolkit_config.gemspec.version
9
+ def default_configuration(toolkit)
10
+ setting(:gemspec, toolkit.gemspec)
11
+ setting(:build_finished_file, toolkit.finished_files.build)
12
+ setting(:tag, toolkit.gemspec.version.to_s)
18
13
  end
19
14
 
20
15
  def define
@@ -28,7 +23,7 @@ module Corundum
28
23
  task :preflight => in_namespace(:not_tagged)
29
24
  task :build => in_namespace(:is_checked_in)
30
25
  in_namespace(:tag, :check_in).each do |taskname|
31
- task taskname => @configuration.build_finished_file
26
+ task taskname => build_finished_file
32
27
  end
33
28
  task :release => in_namespace(:tag, :check_in)
34
29
  end
@@ -9,16 +9,18 @@ module Corundum
9
9
 
10
10
  def default_configuration(*args)
11
11
  super
12
- @configuration.branch = nil
12
+ setting(:branch, nil)
13
13
  end
14
14
 
15
15
  def resolve_configuration
16
- @configuration.branch ||= guess_branch
16
+ @branch ||= guess_branch
17
17
  end
18
18
 
19
19
  def mtn_automate(cmd, *args)
20
20
  result = ""
21
- IO.popen("mtn automate #{cmd} #{args.join(" ")}") do |pipe|
21
+ command = "mtn automate #{cmd} #{args.join(" ")}"
22
+ puts command if verbose
23
+ IO.popen(command) do |pipe|
22
24
  result = pipe.read
23
25
  end
24
26
  result
@@ -75,7 +77,7 @@ module Corundum
75
77
  end
76
78
 
77
79
  def base_revision
78
- mtn_automate("get_base_revision_id")
80
+ mtn_automate("get_base_revision_id").chomp
79
81
  end
80
82
 
81
83
  def guess_branch
@@ -90,10 +92,10 @@ module Corundum
90
92
 
91
93
  in_namespace do
92
94
  task :not_tagged do
93
- items = parse_basic_io(mtn_automate("tags", @configuration.branch))
94
- tags = items.find{|pair| pair[0] == "tag" && pair[1] == @configuration.tag}
95
+ items = parse_basic_io(mtn_automate("tags", branch))
96
+ tags = items.find{|pair| pair[0] == "tag" && pair[1] == tag}
95
97
  unless tags.nil?
96
- fail "Tag #{@configuration.tag} already exists in branch #{@configuration.branch}"
98
+ fail "Tag #{tag} already exists in branch #{branch}"
97
99
  end
98
100
  end
99
101
 
@@ -106,11 +108,11 @@ module Corundum
106
108
  end
107
109
 
108
110
  task :tag do
109
- mtn_automate("cert", base_revision, "tag", @configuration.tag)
111
+ mtn_automate("cert", base_revision, "tag", tag)
110
112
  end
111
113
 
112
114
  task :commit do
113
- run "mtn commit --branch #{@configuration.branch} --message \"Automatic commit: gem built at version #{@configuration.gemspec.version}\""
115
+ sh "mtn commit --branch #{branch} --message \"Automatic commit: gem built at version #{gemspec.version}\""
114
116
  end
115
117
 
116
118
  task :sync do