Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
Add a couple of specs for running metrical
Browse files Browse the repository at this point in the history
  • Loading branch information
iain committed Feb 12, 2012
1 parent 20d6a05 commit cad36e7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .metrics
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby

# For testing that this file gets loaded
puts "Metrics config loaded"

MetricFu::Configuration.run do |config| MetricFu::Configuration.run do |config|
config.metrics -= [ :rcov ] config.metrics -= [ :rcov ]
end end
2 changes: 1 addition & 1 deletion bin/metrical
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby


require "metrical" require "metrical"
Metrical.run(*ARGV) Metrical.run(ARGV.dup)
6 changes: 4 additions & 2 deletions lib/metrical.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
require "metrical/version" require "metrical/version"
require "metrical/options"


require 'rubygems' require 'rubygems'
require 'json' require 'json'
Expand All @@ -11,11 +12,12 @@
module Metrical module Metrical
extend self extend self


def run(*) def run(argv)
options = Options.parse(argv)
load_settings load_settings
load_user_configuration load_user_configuration
run_metric_fu run_metric_fu
open_in_browser open_in_browser if options[:open]
end end


def load_settings(ruby_version = RUBY_VERSION) def load_settings(ruby_version = RUBY_VERSION)
Expand Down
23 changes: 23 additions & 0 deletions lib/metrical/options.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'optparse'

module Metrical
module Options

def self.parse(argv)
options = { :open => true }
opts = OptionParser.new do |opts|

opts.version = Metrical::VERSION

opts.on "--[no-]open", "Automatically open report in browser" do |open|
options[:open] = open
end

end

opts.parse!(argv)
options
end

end
end
5 changes: 2 additions & 3 deletions spec/metrical_spec.rb → spec/configuration_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'bundler/setup' require 'spec_helper'
require 'metrical'


describe Metrical do describe Metrical, "configuration" do


it "won't use rcov under ruby 1.9" do it "won't use rcov under ruby 1.9" do
Metrical.load_settings("1.9.3") Metrical.load_settings("1.9.3")
Expand Down
16 changes: 16 additions & 0 deletions spec/running_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Metrical, "running" do

around do |example|
stdin, stdout, stderr = Open3.popen3("metrical --no-open")
@stdout = stdout.read
@stderr = stderr.read
example.run
end

it "loads the .metrics file" do
@stdout.should include "Metrics config loaded"
end

end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler/setup'
require 'metrical'

0 comments on commit cad36e7

Please sign in to comment.