Skip to content

Commit

Permalink
add support for testing styles in isolation
Browse files Browse the repository at this point in the history
see wiki/Test-Environment#testing-styles-in-isolation
  • Loading branch information
inukshuk committed Apr 28, 2013
1 parent 98fc903 commit 574d0d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
12 changes: 7 additions & 5 deletions spec/repository_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
describe "The CSL Style Repository" do

it "contains independent styles" do
Independents.should_not be_empty
end
unless ENV['CSL_TEST']
it "contains independent styles" do
Independents.should_not be_empty
end

it "contains dependent styles" do
Dependents.should_not be_empty
it "contains dependent styles" do
Dependents.should_not be_empty
end
end

it "does not contain any duplicate file names" do
Expand Down
43 changes: 41 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,55 @@ def load_style(path)
end


# Collect styles to include in this test run.
#
# By default, all *.csl files will be included. If the environment
# variable CSL_TEST is set, only the style files matching the content
# of the variable will be tested; this can be a space separated list
# of files including regular expressions; if CSL_TEST is set to the
# special value `git' only those styles which have been modified since
# the last commit will be tested.
#
# Note that this requires the `git` executable to be available. Also
# note that this will not catch new files which have not yet been
# committed, but only modified files.
#
# Examples:
#
# $ CSL_TEST=git bundle exec rspec spec --format doc
# -> only includes changed styles and using documentation format
#
# $ CSL_TEST="apa.csl vancouver.csl" bundle exec rspec spec
# -> only run test for apa.csl and vancouver.csl
#
# $ CSL_TEST="chicago.*" bundle exec rspec spec
# -> run tests for all styles starting with 'chicago'

STYLE_FILTER = case ENV['CSL_TEST']
when nil
/./
when 'git'
Regexp.new("/(#{`git diff --name-only`.split(/\s+/).join('|')})$")
else
Regexp.new("/(#{ENV['CSL_TEST'].split(/\s+/).join('|')})$")
end

def collect_styles(type = '')
Dir[File.join(STYLE_ROOT, type, '*.csl')].select do |filename|
filename =~ STYLE_FILTER
end
end

print "\nLoading dependent styles"

Dependents = Hash[Dir[File.join(STYLE_ROOT, 'dependent', '*.csl')].each_with_index.map { |path, i|
Dependents = Hash[collect_styles('dependent').each_with_index.map { |path, i|
print '.' if i % 120 == 0
load_style(path)
}]

print "\nLoading independent styles"

Independents = Hash[Dir[File.join(STYLE_ROOT, '*.csl')].each_with_index.map { |path, i|
Independents = Hash[collect_styles.each_with_index.map { |path, i|
print '.' if i % 120 == 0
load_style(path)
}]
Expand Down

0 comments on commit 574d0d6

Please sign in to comment.