Permalink
Browse files

Stretching the customs metaphor

  • Loading branch information...
1 parent e4a748f commit 08b428fa1384c189d4f0a8d36a3f06bc88f601f9 @dbloete dbloete committed Nov 15, 2010
@@ -0,0 +1,6 @@
+module Autoput
+ module Customs
+ class Check
+ end
+ end
+end
@@ -0,0 +1,50 @@
+require "yaml"
+
+module Autoput
+ module Customs
+ class Entry
+ FILE = ".autoput.yml"
+
+ # Inserts new payload into the file and
+ # limits to two payloads per framework.
+ def self.add_payload(payload)
+ c = self.contents
+ payloads = c[payload.framework] || []
+ payloads.unshift({
+ :green => payload.green,
+ :results => payload.results,
+ :run_at => payload.run_at })
+ c[payload.framework] = payloads[0..1]
+ File.open(FILE, "w") { |f| f.write(c.to_yaml) }
+ end
+
+ # Deserializes the runs
+ def self.payloads(framework)
+ (self.contents[framework] || []).map do |attrs|
+ Payload.new(framework, attrs)
+ end
+ end
+
+ private
+
+ # Returns te content of the file as a hash with framework names as keys.
+ # Example file structure:
+ # ---
+ # rspec2:
+ # - :run_at: 2010-11-14 23:15:28.689005 +01:00
+ # :green: true
+ # :results:
+ # - :run_at: 2010-11-14 23:12:21.467073 +01:00
+ # :green: false
+ # :results:
+ # - Testspec for Autoput should fail
+ # - Testspec for Autoput with more detail should fail
+ # - Testspec for Autoput with more detail when stacked should fail
+
+ def self.contents
+ YAML.load(File.read(FILE)) || {}
+ end
+
+ end
+ end
+end
@@ -0,0 +1,40 @@
+module Autoput
+ module Customs
+ class EntryCertificate
+
+ def initialize(new_result, old_result)
+ @new_msg = new_result
+ @old_msg = old_result
+ end
+
+ def caption text
+ first_new_line = text.index("\n")+1
+ text[first_new_line, text.index("\n", first_new_line)]
+ end
+
+ def commit_msg
+ old_specs = specs_to_array @old_msg
+ new_specs = specs_to_array @new_msg
+ commit_msg = caption(@new_msg)
+ new_specs.each do |line|
+ unless old_specs.include? line
+ line[0] = '+'
+ commit_msg += line
+ end
+ end
+ old_specs.each do |line|
+ commit_msg += line unless new_specs.include? line
+ end
+ commit_msg
+ end
+
+ def specs_to_array text
+ specs = []
+ text.each_line do |line|
+ specs << line if line.match(/^-.*/) and not line.match(/.*\(FAILED .*/)
+ end
+ specs
+ end
+ end
+ end
+end
@@ -0,0 +1,16 @@
+require "yaml"
+
+module Autoput
+ module Customs
+ class Payload
+ attr_reader :framework, :results, :green, :run_at
+
+ def initialize(framework, attrs = {})
+ @framework = framework
+ @results = attrs[:results] || []
+ @green = attrs[:green] || false
+ @run_at = attrs[:run_at] || Time.now
+ end
+ end
+ end
+end
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Autoput::Customs::EntryCertificate do
+
+ # it "should work with empty strings and yield empty message" do
+ #
+ # new_result = "MyClass should be epic"
+ # old_result = ""
+ #
+ # Autoput::MessageDiffer.new(new_result, old_result).commit_msg.should == ""
+ # end
+
+end
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Autoput::Customs::Payload do
+
+ before(:each) do
+ @results = ['Autoput should work', 'Autoput should be awesome']
+ end
+
+ describe "self#initialize" do
+
+ context "with hash as argument" do
+
+ subject { Autoput::Customs::Payload.new("cucumber", { :results => @results, :green => false }) }
+
+ its(:framework) { should == "cucumber" }
+ its(:results) { should == @results }
+ its(:green) { should be_false }
+
+ end
+
+ context "with only the framework argument" do
+
+ subject { Autoput::Customs::Payload.new("rspec2") }
+
+ its(:framework) { should == "rspec2" }
+ its(:results) { should be_empty }
+ its(:green) { should be_false }
+
+ end
+
+ end
+
+end

0 comments on commit 08b428f

Please sign in to comment.