start work on spec

This commit is contained in:
John Bintz 2011-03-07 12:39:47 -05:00
parent 34ec07e604
commit b41516c13b
8 changed files with 102 additions and 0 deletions

10
Gemfile
View File

@ -2,3 +2,13 @@ source "http://rubygems.org"
# Specify your gem's dependencies in ruby-avm-library.gemspec
gemspec
group :test do
gem 'autotest'
end
group :mac do
gem 'autotest-fsevent'
gem 'autotest-growl'
end

2
autotest/discover.rb Normal file
View File

@ -0,0 +1,2 @@
Autotest.add_discovery { "rspec2" }

20
lib/avm/creator.rb Normal file
View File

@ -0,0 +1,20 @@
module AVM
class Creator
def initialize
@options = {}
end
def merge!(hash)
@options.merge!(hash)
end
def method_missing(key, *opts)
if key.to_s[-1..-1] == '='
@options[key.to_s[0..-2].to_sym] = opts.first
else
@options[key]
end
end
end
end

12
lib/avm/image.rb Normal file
View File

@ -0,0 +1,12 @@
require 'avm/creator'
module AVM
class Image
attr_reader :creator
def initialize
@creator = AVM::Creator.new
end
end
end

View File

@ -18,4 +18,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_development_dependency 'rspec'
s.add_development_dependency 'mocha'
end

36
spec/avm/creator_spec.rb Normal file
View File

@ -0,0 +1,36 @@
require 'spec_helper'
require 'avm/image'
require 'avm/creator'
describe AVM::Creator do
let(:image) { AVM::Image.new }
let(:creator) { image.creator }
let(:name) { 'Space Telescope Science Institute' }
let(:url) { 'http://www.stsci.edu/' }
let(:rights) { 'Public Domain' }
subject { creator }
def self.can_read_properties
its(:name) { should == name }
its(:url) { should == url }
its(:rights) { should == rights }
end
describe '#merge!' do
before { creator.merge!(:name => name, :url => url, :rights => rights) }
can_read_properties
end
describe 'setters' do
before {
creator.name = name
creator.url = url
creator.rights = rights
}
can_read_properties
end
end

15
spec/avm/image_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require 'spec_helper'
require 'avm/image'
describe AVM::Image do
let(:image) { self.class.describes.new }
subject { image }
describe '#initialize' do
it { should be_a_kind_of(AVM::Image) }
its(:creator) { should be_a_kind_of(AVM::Creator) }
end
end

4
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,4 @@
RSpec.configure do |config|
config.mock_with :mocha
end