From b41516c13ba534c8801abf4766fa7ff180a388a2 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 7 Mar 2011 12:39:47 -0500 Subject: [PATCH] start work on spec --- Gemfile | 10 ++++++++++ autotest/discover.rb | 2 ++ lib/avm/creator.rb | 20 ++++++++++++++++++++ lib/avm/image.rb | 12 ++++++++++++ ruby-avm-library.gemspec | 3 +++ spec/avm/creator_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ spec/avm/image_spec.rb | 15 +++++++++++++++ spec/spec_helper.rb | 4 ++++ 8 files changed, 102 insertions(+) create mode 100644 autotest/discover.rb create mode 100644 lib/avm/creator.rb create mode 100644 lib/avm/image.rb create mode 100644 spec/avm/creator_spec.rb create mode 100644 spec/avm/image_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Gemfile b/Gemfile index 201b0d7..efde300 100644 --- a/Gemfile +++ b/Gemfile @@ -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 + diff --git a/autotest/discover.rb b/autotest/discover.rb new file mode 100644 index 0000000..de32a01 --- /dev/null +++ b/autotest/discover.rb @@ -0,0 +1,2 @@ +Autotest.add_discovery { "rspec2" } + diff --git a/lib/avm/creator.rb b/lib/avm/creator.rb new file mode 100644 index 0000000..2239744 --- /dev/null +++ b/lib/avm/creator.rb @@ -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 + diff --git a/lib/avm/image.rb b/lib/avm/image.rb new file mode 100644 index 0000000..1e99bd3 --- /dev/null +++ b/lib/avm/image.rb @@ -0,0 +1,12 @@ +require 'avm/creator' + +module AVM + class Image + attr_reader :creator + + def initialize + @creator = AVM::Creator.new + end + end +end + diff --git a/ruby-avm-library.gemspec b/ruby-avm-library.gemspec index 71910fe..beb794d 100644 --- a/ruby-avm-library.gemspec +++ b/ruby-avm-library.gemspec @@ -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 diff --git a/spec/avm/creator_spec.rb b/spec/avm/creator_spec.rb new file mode 100644 index 0000000..0ba4433 --- /dev/null +++ b/spec/avm/creator_spec.rb @@ -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 diff --git a/spec/avm/image_spec.rb b/spec/avm/image_spec.rb new file mode 100644 index 0000000..ff60f5e --- /dev/null +++ b/spec/avm/image_spec.rb @@ -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 + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..eba562b --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +RSpec.configure do |config| + config.mock_with :mocha +end +