Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

Commit

Permalink
Fixed specs and used let/subject.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Apr 6, 2011
1 parent c4581f0 commit c641940
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
10 changes: 2 additions & 8 deletions spec/data_paths_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@

describe DataPaths do
describe "instance methods" do
include DataPaths

before(:all) do
@context = self
end
subject { Class.new { include DataPaths } }

it_should_behave_like "Methods"
end

describe "class methods" do
before(:all) do
@context = DataClass
end
subject { DataClass }

it_should_behave_like "Methods"
end
Expand Down
21 changes: 12 additions & 9 deletions spec/finders_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
require 'data_paths/finders'

require 'spec_helper'
require 'helpers/data'

require 'data_paths/finders'

describe DataPaths::Finders do
before(:all) do
@example = DataClass.new
subject do
Class.new {
include DataPaths
include DataPaths::Finders
}.new
end

it "should find a file" do
@example.find_data_file('one.txt').should == File.join(Helpers::DATA_DIRS[0],'one.txt')
subject.find_data_file('one.txt').should == File.join(Helpers::DATA_DIRS[0],'one.txt')
end

it "should find a directory" do
@example.find_data_dir('dir').should == File.join(Helpers::DATA_DIRS[0],'dir')
subject.find_data_dir('dir').should == File.join(Helpers::DATA_DIRS[0],'dir')
end

it "should find all matching files" do
@example.all_data_files('dir/two.txt').should == [
subject.all_data_files('dir/two.txt').should == [
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
]
end

it "should find all matching directories" do
@example.all_data_dirs('dir').should == [
subject.all_data_dirs('dir').should == [
File.join(Helpers::DATA_DIRS[0],'dir'),
File.join(Helpers::DATA_DIRS[1],'dir')
]
end

it "should find all paths matching a pattern" do
@example.data_glob('*/*.txt').should == [
subject.data_glob('*/*.txt').should == [
File.join(Helpers::DATA_DIRS[0],'dir','two.txt'),
File.join(Helpers::DATA_DIRS[1],'dir','two.txt')
]
Expand Down
8 changes: 4 additions & 4 deletions spec/methods_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
shared_examples_for "Methods" do
before(:all) do
Helpers::DATA_DIRS.each do |dir|
@context.register_data_dir dir
subject.register_data_dir dir
end
end

it "should list data directories" do
Helpers::DATA_DIRS.each do |dir|
@context.data_paths.should include(dir)
subject.data_paths.should include(dir)
end
end

it "should prevent the addition of non-existant directories" do
lambda {
@context.register_data_dir 'lol'
subject.register_data_dir 'lol'
}.should raise_error(RuntimeError)
end

it "should prevent the addition of non-directories" do
lambda {
@context.register_data_dir __FILE__
subject.register_data_dir __FILE__
}.should raise_error(RuntimeError)
end
end

0 comments on commit c641940

Please sign in to comment.