rspec-pubsub-formatter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rspec-pubsub-formatter.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ rspec-pubsub-formatter
2
+ ======================
3
+
4
+ Publishes a json serialized hash to a redis pubsub channel (`pubsub_formatter`
5
+ by default) with the following data:
6
+
7
+ {
8
+ :total_example_count => 4,
9
+ :run_example_count => 2,
10
+ :failure_count => 1,
11
+ :pending_count => 0,
12
+ :percent_complete => 50
13
+ }
14
+
15
+ The formatter inherits from the `RSpec::Core::Formatters::ProgressFormatter` and
16
+ maintains its behavior of reporting, in addition to publishing to redis.
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => [:spec]
@@ -0,0 +1,89 @@
1
+ require 'rspec/core/formatters/progress_formatter'
2
+ require 'redis'
3
+ require 'json'
4
+
5
+ module RSpecPubsub
6
+ class Formatter < RSpec::Core::Formatters::ProgressFormatter
7
+ attr_reader :channel
8
+
9
+ def initialize(output)
10
+ super
11
+ @channel = Channel.new
12
+ end
13
+
14
+ def start(example_count)
15
+ super
16
+ publish_status
17
+ end
18
+
19
+ def example_passed(example)
20
+ super
21
+ publish_status
22
+ end
23
+
24
+ def example_pending(example)
25
+ super
26
+ publish_status
27
+ end
28
+
29
+ def example_failed(example)
30
+ super
31
+ publish_status
32
+ end
33
+
34
+ private
35
+
36
+ def status
37
+ {
38
+ :total_example_count => example_count,
39
+ :run_example_count => run_example_count,
40
+ :failure_count => failure_count,
41
+ :pending_count => pending_count,
42
+ :percent_complete => percent_complete
43
+ }
44
+ end
45
+
46
+ def run_example_count
47
+ examples.length
48
+ end
49
+
50
+ def failure_count
51
+ failed_examples.length
52
+ end
53
+
54
+ def pending_count
55
+ pending_examples.length
56
+ end
57
+
58
+ def percent_complete
59
+ begin
60
+ ((run_example_count / example_count.to_f ) * 100).to_i
61
+ rescue FloatDomainError
62
+ 0
63
+ end
64
+ end
65
+
66
+ def publish_status
67
+ channel.publish(status)
68
+ end
69
+ end
70
+
71
+ class Channel
72
+ attr_reader :redis
73
+
74
+ class << self
75
+ attr_writer :channel_name
76
+ def channel_name
77
+ @channel_name || "pubsub_formatter"
78
+ end
79
+ end
80
+
81
+ def initialize
82
+ @redis = Redis.new
83
+ end
84
+
85
+ def publish(status)
86
+ redis.publish(self.class.channel_name, status.to_json)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ module Rspec
2
+ module Pubsub
3
+ module Formatter
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require "rspec-pubsub-formatter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rspec-pubsub-formatter"
7
+ s.version = Rspec::Pubsub::Formatter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brendon Murphy"]
10
+ s.email = ["xternal1+github@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Publish rspec status from a spec run into redis}
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "rspec-pubsub-formatter"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rspec", ">= 2"
22
+ s.add_dependency "redis", "~> 2.2.2"
23
+ s.add_dependency "json"
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'rspec-pubsub-formatter'
2
+
3
+ describe RSpecPubsub::Channel do
4
+ let(:redis) { stub("Redis") }
5
+ let(:status) { { :foo => "bar", :fizz => "buzz" } }
6
+
7
+ before do
8
+ Redis.stub(:new).and_return(redis)
9
+ end
10
+
11
+ it "publishes the provided hash to redis as json" do
12
+ redis.should_receive(:publish).with("pubsub_formatter", status.to_json)
13
+ subject.publish(status)
14
+ end
15
+
16
+ it "allows changing the channel name via the class" do
17
+ RSpecPubsub::Channel.channel_name = "blam"
18
+ redis.should_receive(:publish).with("blam", status.to_json)
19
+ subject.publish(status)
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec-pubsub-formatter'
2
+
3
+ describe RSpecPubsub::Formatter do
4
+ let(:output) { StringIO.new }
5
+ let(:channel) { stub("Channel", :publish => true) }
6
+ subject{ RSpecPubsub::Formatter.new(output) }
7
+
8
+ before do
9
+ RSpecPubsub::Channel.stub(:new).and_return(channel)
10
+ end
11
+
12
+ it "publishes its status with example count on start" do
13
+ channel.should_receive(:publish).with(hash_including(:total_example_count => 5))
14
+ subject.start(5)
15
+ end
16
+
17
+ it "publishes the count of failed examples" do
18
+ channel.should_receive(:publish).with(hash_including(:failure_count => 1))
19
+ channel.should_receive(:publish).with(hash_including(:failure_count => 2))
20
+ 2.times { subject.example_failed(stub) }
21
+ end
22
+
23
+ it "publishes the count of pending examples" do
24
+ channel.should_receive(:publish).with(hash_including(:pending_count => 1))
25
+ channel.should_receive(:publish).with(hash_including(:pending_count => 2))
26
+ 2.times { subject.example_pending(stub) }
27
+ end
28
+
29
+ it "publishes the count of examples run so far" do
30
+ channel.should_receive(:publish).with(hash_including(:run_example_count => 1))
31
+ channel.should_receive(:publish).with(hash_including(:run_example_count => 2))
32
+ 2.times do
33
+ example = stub
34
+ subject.example_started(example)
35
+ subject.example_failed(example)
36
+ end
37
+ end
38
+
39
+ it "publishes the percentage of examples completed" do
40
+ subject.start(2)
41
+ channel.should_receive(:publish).with(hash_including(:percent_complete => 50))
42
+ channel.should_receive(:publish).with(hash_including(:percent_complete => 100))
43
+ 2.times do
44
+ example = stub
45
+ subject.example_started(example)
46
+ subject.example_passed(example)
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-pubsub-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brendon Murphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2157375380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157375380
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis
27
+ requirement: &2157374880 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2157374880
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &2157396260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2157396260
47
+ description: Publish rspec status from a spec run into redis
48
+ email:
49
+ - xternal1+github@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - lib/rspec-pubsub-formatter.rb
59
+ - lib/rspec-pubsub-formatter/version.rb
60
+ - rspec-pubsub-formatter.gemspec
61
+ - spec/rspec_pubsub_channel_spec.rb
62
+ - spec/rspec_pubsub_formatter_spec.rb
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project: rspec-pubsub-formatter
83
+ rubygems_version: 1.8.11
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Publish rspec status from a spec run into redis
87
+ test_files: []