Skip to content

Commit

Permalink
Issue #68
Browse files Browse the repository at this point in the history
* lib/jaribio/plan.rb: now inherits from RemoteObject
* lib/jaribio/record.rb (initialize): fixed some bugs
* lib/jaribio/remote_object.rb: new file, this is a base class for our
active_resource objects that will automatically add the needed api_key
query parameter as needed
* lib/jaribio_formatter.rb: fixing some requires
* spec/lib/jaribio/record_spec.rb: new spec
* spec/lib/jaribio/rspec_formatter_spec.rb: fixed the spec related to
results which was wrong before
* spec/spec_helper.rb: require in jaribio_formatter instead of
jaribio-formatter
  • Loading branch information
Brian Jones committed Mar 6, 2012
1 parent 397d679 commit 93c2ed4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
12 changes: 2 additions & 10 deletions jaribio_formatter/lib/jaribio/plan.rb
@@ -1,15 +1,7 @@
require 'active_resource'
require 'jaribio/remote_object'

module Jaribio
class Plan < ActiveResource::Base
# site is set as needed by formatters

# use json, not xml
self.format = :json

# set timeout to 5 seconds (does not affect DNS lookups generally)
self.timeout = 5

class Plan < RemoteObject
# Usage: Jaribio::Plan.find(1, :params => {'api_key' => 'asdf'})
end
end
Expand Down
8 changes: 4 additions & 4 deletions jaribio_formatter/lib/jaribio/record.rb
Expand Up @@ -5,10 +5,10 @@ class Record

attr_accessor :key, :description, :state

def initialize(args)
key = args[:key]
description = args[:description]
state = args[:state]
def initialize(args = {})
self.key = args[:key]
self.description = args[:description]
self.state = args[:state]
end

def failed?
Expand Down
23 changes: 23 additions & 0 deletions jaribio_formatter/lib/jaribio/remote_object.rb
@@ -0,0 +1,23 @@
require 'active_resource'
require 'active_support/core_ext/class/attribute_accessors'

module Jaribio
class RemoteObject < ActiveResource::Base
cattr_accessor :api_key

# use json, not xml
self.format = :json

# set timeout to 5 seconds (does not affect DNS lookups generally)
self.timeout = 5

class << self
def query_string(options)
options = {} if options.nil?
options[:api_key] = api_key unless api_key.nil?
super(options)
end
end

end
end
2 changes: 1 addition & 1 deletion jaribio_formatter/lib/jaribio_formatter.rb
@@ -1,3 +1,3 @@
%w(rspec_formatter.rb record.rb formatter/version.rb).each do |file|
%w(remote_object plan rspec_formatter record formatter/version).each do |file|
require File.expand_path(File.join(File.dirname(__FILE__), 'jaribio', file))
end
28 changes: 28 additions & 0 deletions jaribio_formatter/spec/lib/jaribio/record_spec.rb
@@ -0,0 +1,28 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe "Jaribio::Record" do
describe "#failed?" do
it "is true when not set" do
Jaribio::Record.new().failed?.should be_true
end

it "is true when state is FAIL" do
Jaribio::Record.new(:state => Jaribio::Record::FAIL).failed?.should be_true
end

it "is false when state is PASS" do
Jaribio::Record.new(:state => Jaribio::Record::PASS).failed?.should be_false
end
end

describe "#eql?" do
let(:attributes) { Hash.new(:key => 'key', :description => 'description', :state => Jaribio::Record::PASS) }

it "true if attributes are eql?" do
a = Jaribio::Record.new(attributes)
b = Jaribio::Record.new(attributes)
a.should eql(b)
end
end

end
10 changes: 5 additions & 5 deletions jaribio_formatter/spec/lib/jaribio/rspec_formatter_spec.rb
Expand Up @@ -86,11 +86,11 @@ def verify_key_and_description(example, expected_key, expected_description)

it "values are a hash with description and failed state" do
formatter.results.should eql({
'e2' => Jaribio::Record.new(:key => 'e2', :description => 'object example 2', :failed => true),
'g1' => Jaribio::Record.new(:key => 'g1', :description => 'object subgroup', :failed => true),
'g1e2' => Jaribio::Record.new(:key => 'g1e2', :description => 'object subgroup example 2', :failed => true),
'object' => Jaribio::Record.new(:key => 'object', :description => 'object', :failed => true),
'object subgroup2' => Jaribio::Record.new(:key => 'object subgroup2', :description => 'object subgroup2', :failed => true),
'e2' => Jaribio::Record.new(:key => 'e2', :description => 'object example 2', :state => Jaribio::Record::FAIL),
'g1' => Jaribio::Record.new(:key => 'g1', :description => 'object subgroup', :state => Jaribio::Record::FAIL),
'g1e2' => Jaribio::Record.new(:key => 'g1e2', :description => 'object subgroup example 2', :state => Jaribio::Record::FAIL),
'object' => Jaribio::Record.new(:key => 'object', :description => 'object', :state => Jaribio::Record::FAIL),
'object subgroup2' => Jaribio::Record.new(:key => 'object subgroup2', :description => 'object subgroup2', :state => Jaribio::Record::FAIL),
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion jaribio_formatter/spec/spec_helper.rb
Expand Up @@ -7,7 +7,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'jaribio-formatter'
require 'jaribio_formatter'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Expand Down

0 comments on commit 93c2ed4

Please sign in to comment.