webspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webspec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Grzesiek Kolodziejczyk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Webspec
2
+
3
+ Reports RSpec results to a web api for online browsing.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => [:spec]
data/lib/webspec.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "webspec/version"
2
+ require "webspec/formatter"
3
+ require "httparty"
4
+ require "json"
5
+
6
+ module Webspec
7
+ include HTTParty
8
+
9
+ class << self
10
+ attr_accessor :api_key
11
+
12
+ def base_url
13
+ ENV['WEBSPEC_URL'] || "https://webspec.shellyapp.com"
14
+ end
15
+
16
+ def configure_rspec
17
+ RSpec.configuration.add_formatter(Webspec::Formatter)
18
+ end
19
+
20
+ def report(output_hash)
21
+ FakeWeb.allow_net_connect = true if defined?(FakeWeb)
22
+ url = "#{base_url}/projects/#{api_key}/runs.json"
23
+ post(url, :body => {:run => output_hash})
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,112 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+
3
+ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
4
+ attr_reader :output_hash
5
+
6
+ def initialize(output)
7
+ super
8
+ @output_hash = {:elements => []}
9
+ @example_group_stack = []
10
+ @parent_example_group = nil
11
+ end
12
+
13
+ def message(message)
14
+ (@output_hash[:messages] ||= []) << message
15
+ end
16
+
17
+ def example_group_started(example_group)
18
+ @example_group_stack.push(@parent_example_group) if @parent_example_group
19
+ @parent_example_group = @example_group
20
+ @example_group = {
21
+ :type => "example_group",
22
+ :description => example_group.description,
23
+ :elements => []
24
+ }
25
+ end
26
+
27
+ def example_group_finished(example_group)
28
+ return unless @example_group
29
+ if @parent_example_group
30
+ @parent_example_group[:elements] << @example_group
31
+ else
32
+ @output_hash[:elements] << @example_group
33
+ end
34
+
35
+ @example_group = @parent_example_group
36
+ @parent_example_group = @example_group_stack.pop
37
+ end
38
+
39
+ def example_passed(example)
40
+ example_finished(example)
41
+ end
42
+
43
+ def example_failed(example)
44
+ example_finished(example)
45
+ end
46
+
47
+ def example_pending(example)
48
+ example_finished(example)
49
+ end
50
+
51
+ def example_finished(example)
52
+ @example_group[:elements] << example_metadata(example)
53
+ end
54
+
55
+ def dump_summary(duration, example_count, failure_count, pending_count)
56
+ super(duration, example_count, failure_count, pending_count)
57
+ @output_hash[:summary] = {
58
+ :duration => duration,
59
+ :example_count => example_count,
60
+ :failure_count => failure_count,
61
+ :pending_count => pending_count
62
+ }
63
+ @output_hash[:summary_line] = summary_line(example_count, failure_count, pending_count)
64
+
65
+ # Don't print out profiled info if there are failures, it just clutters the output
66
+ dump_profile if profile_examples? && failure_count == 0
67
+ end
68
+
69
+ def summary_line(example_count, failure_count, pending_count)
70
+ summary = pluralize(example_count, "example")
71
+ summary << ", " << pluralize(failure_count, "failure")
72
+ summary << ", #{pending_count} pending" if pending_count > 0
73
+ summary
74
+ end
75
+
76
+ def example_metadata(example)
77
+ {
78
+ :type => "example",
79
+ :description => example.description,
80
+ :full_description => example.full_description,
81
+ :status => example.execution_result[:status],
82
+ :example_group => example.example_group.description,
83
+ :execution_result => example.execution_result,
84
+ :file_path => example.file_path,
85
+ :line_number => example.metadata[:line_number],
86
+ }.tap do |hash|
87
+ if e=example.exception
88
+ hash[:exception] = {
89
+ :class => e.class.name,
90
+ :message => e.message,
91
+ :backtrace => e.backtrace,
92
+ }
93
+ end
94
+ end
95
+ end
96
+
97
+ def stop
98
+ super
99
+ end
100
+
101
+ def close
102
+ @output_hash[:env] = {
103
+ :user => ENV['USER'],
104
+ :ruby_platform => RUBY_PLATFORM,
105
+ :ruby_engine => RUBY_ENGINE,
106
+ :ruby_version => RUBY_VERSION,
107
+ :ruby_patchlevel => RUBY_PATCHLEVEL
108
+ }
109
+
110
+ Webspec.report(@output_hash)
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module Webspec
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'webspec'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Webspec::Formatter do
4
+ let(:formatter) { Webspec::Formatter.new(nil) }
5
+
6
+ it "should initialize empty output hash" do
7
+ formatter.output_hash.should == {:elements => []}
8
+ end
9
+
10
+ it "should add message to output_hash" do
11
+ formatter.message("test message")
12
+ formatter.output_hash[:messages].should == ["test message"]
13
+ end
14
+
15
+ it "should add summary to output hash" do
16
+ formatter.dump_summary(1.5, 10, 1, 2)
17
+ formatter.output_hash[:summary].should eql({
18
+ :duration => 1.5,
19
+ :example_count => 10,
20
+ :failure_count => 1,
21
+ :pending_count => 2
22
+ })
23
+ formatter.output_hash[:summary_line].should
24
+ eql("10 examples, 1 failure, 2 pending")
25
+ end
26
+
27
+ it "should add examples to output hash"
28
+
29
+ describe "on close" do
30
+ it "should report the run to Webspec" do
31
+ Webspec.should_receive(:report).with(formatter.output_hash)
32
+ formatter.close
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Webspec do
4
+ describe "configure_rspec" do
5
+ it "should add Webspec::Formatter to RSpec configuration" do
6
+ configuration = mock
7
+ RSpec.should_receive(:configuration).and_return(configuration)
8
+ configuration.should_receive(:add_formatter).with(Webspec::Formatter)
9
+ Webspec.configure_rspec
10
+ end
11
+ end
12
+
13
+ describe "report" do
14
+ it "should send output_hash to webspec web app" do
15
+ Webspec.stub(:api_key => "abc123")
16
+ Webspec.should_receive(:post).
17
+ with("https://webspec.shellyapp.com/projects/abc123/runs.json",
18
+ {:body => {:run => {:a => :b}}}).and_return(true)
19
+ Webspec.report({:a => :b})
20
+ end
21
+ end
22
+ end
data/webspec.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webspec/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "webspec"
8
+ gem.version = Webspec::VERSION
9
+ gem.authors = ["Grzesiek Kołodziejczyk"]
10
+ gem.email = ["gk@code-fu.pl"]
11
+ gem.summary = "Report rspec results to webspec"
12
+ gem.homepage = "https://github.com/grk/webspec/"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_runtime_dependency "rspec-core", "~> 2.11"
20
+ gem.add_runtime_dependency "httparty"
21
+
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec", "~> 2.11"
24
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Grzesiek Kołodziejczyk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.11'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.11'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.11'
78
+ description:
79
+ email:
80
+ - gk@code-fu.pl
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/webspec.rb
91
+ - lib/webspec/formatter.rb
92
+ - lib/webspec/version.rb
93
+ - spec/spec_helper.rb
94
+ - spec/webspec_formatter_spec.rb
95
+ - spec/webspec_spec.rb
96
+ - webspec.gemspec
97
+ homepage: https://github.com/grk/webspec/
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 726502925257515232
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 726502925257515232
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.24
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Report rspec results to webspec
127
+ test_files:
128
+ - spec/spec_helper.rb
129
+ - spec/webspec_formatter_spec.rb
130
+ - spec/webspec_spec.rb