webspec 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
1
  require "webspec/version"
2
2
  require "webspec/formatter"
3
+ require "webspec/run"
4
+ require "webspec/example_group"
5
+ require "webspec/example"
3
6
  require "httparty"
4
7
  require "json"
5
8
 
@@ -17,10 +20,53 @@ module Webspec
17
20
  RSpec.configuration.add_formatter(Webspec::Formatter)
18
21
  end
19
22
 
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})
23
+ def create_run(run_params = {})
24
+ allow_net_connect do
25
+ url = "#{base_url}/projects/#{api_key}/runs.json"
26
+ response = post(url, :body => {:run => run_params})
27
+ Webspec::Run.new(response.to_hash)
28
+ end
29
+ end
30
+
31
+ def update_run(run_id, run_params = {})
32
+ allow_net_connect do
33
+ url = "#{base_url}/projects/#{api_key}/runs/#{run_id}.json"
34
+ response = put(url, :body => {:run => run_params})
35
+ Webspec::Run.new(response.to_hash)
36
+ end
37
+ end
38
+
39
+ def create_example_group(example_group_params, run, parent = nil)
40
+ allow_net_connect do
41
+ url = "#{base_url}/projects/#{api_key}/runs/#{run.id}/example_groups.json"
42
+ response = post(url, :body => {
43
+ :example_group => example_group_params,
44
+ :parent_id => (parent.id if parent)
45
+ })
46
+ Webspec::ExampleGroup.new(response.to_hash.merge(:run => run))
47
+ end
48
+ end
49
+
50
+ def create_example(example_params, run, parent = nil)
51
+ allow_net_connect do
52
+ url = "#{base_url}/projects/#{api_key}/runs/#{run.id}/examples.json"
53
+ response = post(url, :body => {
54
+ :example => example_params,
55
+ :parent_id => (parent.id if parent)
56
+ })
57
+ Webspec::Example.new(response.to_hash.merge(:run => run))
58
+ end
59
+ end
60
+
61
+ def allow_net_connect
62
+ if defined?(FakeWeb)
63
+ allow_net_connect = FakeWeb.allow_net_connect
64
+ FakeWeb.allow_net_connect = true
65
+ yield
66
+ FakeWeb.allow_net_connect = allow_net_connect
67
+ else
68
+ yield
69
+ end
24
70
  end
25
71
  end
26
72
  end
@@ -0,0 +1,10 @@
1
+ module Webspec
2
+ class Example
3
+ attr_accessor :id, :run
4
+
5
+ def initialize(params = {})
6
+ @id = params["_id"]
7
+ @run = params[:run]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Webspec
2
+ class ExampleGroup
3
+ attr_accessor :id, :run, :parent
4
+
5
+ def initialize(params = {})
6
+ @id = params["_id"]
7
+ @run = params[:run]
8
+ end
9
+
10
+ def create_example_group(example_group)
11
+ example_group = Webspec.create_example_group(example_group, run, self)
12
+ example_group.parent = self
13
+ example_group
14
+ end
15
+
16
+ def create_example(example)
17
+ Webspec.create_example(example, run, self)
18
+ end
19
+ end
20
+ end
@@ -5,9 +5,9 @@ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
5
5
 
6
6
  def initialize(output)
7
7
  super
8
- @output_hash = {:elements => []}
9
- @example_group_stack = []
10
- @parent_example_group = nil
8
+ @run = Webspec.create_run
9
+ @output_hash = {}
10
+ @example_group = @run
11
11
  end
12
12
 
13
13
  def message(message)
@@ -15,25 +15,13 @@ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
15
15
  end
16
16
 
17
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
- }
18
+ @example_group = @example_group.create_example_group({
19
+ :description => example_group.description
20
+ })
25
21
  end
26
22
 
27
23
  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
24
+ @example_group = @example_group.parent
37
25
  end
38
26
 
39
27
  def example_passed(example)
@@ -49,7 +37,8 @@ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
49
37
  end
50
38
 
51
39
  def example_finished(example)
52
- @example_group[:elements] << example_metadata(example)
40
+ puts "example_finished: example_group: #{@example_group}"
41
+ @example_group.create_example(example_metadata(example))
53
42
  end
54
43
 
55
44
  def dump_summary(duration, example_count, failure_count, pending_count)
@@ -75,7 +64,6 @@ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
75
64
 
76
65
  def example_metadata(example)
77
66
  {
78
- :type => "example",
79
67
  :description => example.description,
80
68
  :full_description => example.full_description,
81
69
  :status => example.execution_result[:status],
@@ -107,6 +95,6 @@ class Webspec::Formatter < RSpec::Core::Formatters::BaseFormatter
107
95
  :ruby_patchlevel => RUBY_PATCHLEVEL
108
96
  }
109
97
 
110
- Webspec.report(@output_hash)
98
+ @run.update(@output_hash)
111
99
  end
112
100
  end
@@ -0,0 +1,23 @@
1
+ module Webspec
2
+ class Run
3
+ attr_accessor :id
4
+
5
+ def initialize(params)
6
+ @id = params["_id"]
7
+ end
8
+
9
+ def create_example_group(example_group)
10
+ example_group = Webspec.create_example_group(example_group, self)
11
+ example_group.parent = self
12
+ example_group
13
+ end
14
+
15
+ def create_example(example)
16
+ Webspec.create_example(example, self)
17
+ end
18
+
19
+ def update(params)
20
+ Webspec.update_run(id, params)
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Webspec
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,10 +3,6 @@ require 'spec_helper'
3
3
  describe Webspec::Formatter do
4
4
  let(:formatter) { Webspec::Formatter.new(nil) }
5
5
 
6
- it "should initialize empty output hash" do
7
- formatter.output_hash.should == {:elements => []}
8
- end
9
-
10
6
  it "should add message to output_hash" do
11
7
  formatter.message("test message")
12
8
  formatter.output_hash[:messages].should == ["test message"]
@@ -25,11 +21,4 @@ describe Webspec::Formatter do
25
21
  end
26
22
 
27
23
  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
24
  end
@@ -10,13 +10,14 @@ describe Webspec do
10
10
  end
11
11
  end
12
12
 
13
- describe "report" do
14
- it "should send output_hash to webspec web app" do
13
+ describe ".create_run" do
14
+ it "should create new run in webspec web app" do
15
15
  Webspec.stub(:api_key => "abc123")
16
16
  Webspec.should_receive(:post).
17
17
  with("https://webspec.shellyapp.com/projects/abc123/runs.json",
18
- {:body => {:run => {:a => :b}}}).and_return(true)
19
- Webspec.report({:a => :b})
18
+ {:body => {:run => {:a => :b}}}).and_return({"_id" => "123"})
19
+ Webspec::Run.should_receive(:new).with({"_id" => "123"})
20
+ Webspec.create_run({:a => :b})
20
21
  end
21
22
  end
22
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core
@@ -88,7 +88,10 @@ files:
88
88
  - README.md
89
89
  - Rakefile
90
90
  - lib/webspec.rb
91
+ - lib/webspec/example.rb
92
+ - lib/webspec/example_group.rb
91
93
  - lib/webspec/formatter.rb
94
+ - lib/webspec/run.rb
92
95
  - lib/webspec/version.rb
93
96
  - spec/spec_helper.rb
94
97
  - spec/webspec_formatter_spec.rb
@@ -108,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
111
  version: '0'
109
112
  segments:
110
113
  - 0
111
- hash: 726502925257515232
114
+ hash: -1030159315617042846
112
115
  required_rubygems_version: !ruby/object:Gem::Requirement
113
116
  none: false
114
117
  requirements:
@@ -117,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
120
  version: '0'
118
121
  segments:
119
122
  - 0
120
- hash: 726502925257515232
123
+ hash: -1030159315617042846
121
124
  requirements: []
122
125
  rubyforge_project:
123
126
  rubygems_version: 1.8.24