From 35b2177c7194ebaa915675987e7dfcdc97fc252e Mon Sep 17 00:00:00 2001 From: Jan Renz Date: Wed, 17 Jun 2015 15:29:35 +0200 Subject: [PATCH] Add mocha adpater --- lib/mocha_adapter.rb | 16 ++++++++++++++++ spec/lib/mocha_adapter_spec.rb | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/mocha_adapter.rb create mode 100644 spec/lib/mocha_adapter_spec.rb diff --git a/lib/mocha_adapter.rb b/lib/mocha_adapter.rb new file mode 100644 index 00000000..2d5f41cd --- /dev/null +++ b/lib/mocha_adapter.rb @@ -0,0 +1,16 @@ +class MochaAdapter < TestingFrameworkAdapter + SUCCESS_REGEXP = /(\d+) passing/ + FAILURES_REGEXP = /(\d+) failing/ + + def self.framework_name + 'Mocha' + end + + def parse_output(output) + matches_success = SUCCESS_REGEXP.match(output[:stderr]) + matches_failed = FAILURES_REGEXP.match(output[:stderr]) + failed = matches_failed ? matches_failed.captures.try(:first).to_i : 0 + success = matches_success ? matches_success.captures.try(:first).to_i : 0 + {count: success+failed, failed: failed} + end +end diff --git a/spec/lib/mocha_adapter_spec.rb b/spec/lib/mocha_adapter_spec.rb new file mode 100644 index 00000000..ab2f74f4 --- /dev/null +++ b/spec/lib/mocha_adapter_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +describe MochaAdapter do + let(:adapter) { described_class.new } + let(:count) { 42 } + let(:failed) { 25 } + let(:stderr) { "#{count-failed} passing (20ms)\n\n#{failed} failing" } + + describe '#parse_output' do + it 'returns the correct numbers' do + expect(adapter.parse_output(stderr: stderr)).to eq(count: count, failed: failed) + end + end +end