Skip to content

Commit

Permalink
Adding fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
brymck committed Mar 20, 2012
1 parent a0d0fc7 commit 55d2470
Show file tree
Hide file tree
Showing 7 changed files with 1,654 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,5 +1,6 @@
.DS_Store
.sass-cache
ext/
spec/**/*.js
spec/js/*.js
spec/js/helpers/*.js
*.zip
11 changes: 6 additions & 5 deletions Rakefile
Expand Up @@ -19,7 +19,7 @@ end

def verify_extension_structure
verify_directory EXTENSION_DIR
%w(css img js).each do |subdirectory|
%w(css img js js/content).each do |subdirectory|
verify_directory File.join(EXTENSION_DIR, subdirectory)
end
end
Expand All @@ -40,13 +40,14 @@ def compile_sources(input_type, output_type, opts = {})
}.merge(opts)

output_dir = File.join(EXTENSION_DIR, opts[:output_dir], (opts[:top_level] ? "" : output_type))
input_dir = File.join(SOURCE_DIR, opts[:input_dir])
input_dir = File.join(SOURCE_DIR, opts[:input_dir], input_type)

puts "#{input_type} => #{output_type}"
Dir[File.join(input_dir, input_type, "*.#{input_type}")].each do |path|
Dir[File.join(input_dir, "**", "*.#{input_type}")].each do |path|
sub_path = path.sub(input_dir, "")
output_name = "#{File.basename(path, ".*")}.#{output_type}"
output_path = File.join(output_dir, output_name)
relative_path = File.join(opts[:output_dir], output_name).sub(/^[\/.]+/, "")
relative_path = File.join(File.dirname(sub_path), output_name).sub(/^[\/.]+/, "")
output_path = File.join(output_dir, relative_path)

File.open(output_path, "w") do |handle|
puts " #{relative_path}"
Expand Down
25 changes: 25 additions & 0 deletions spec/coffee/helpers/spec_helper.coffee
@@ -0,0 +1,25 @@
clear_fixtures = ->
div = document.getElementById("fixtures")
while div.hasChildNodes()
div.removeChild div.firstChild

div_for_fixtures = ->
div = document.getElementById("fixtures")
unless div?
div = document.createElement("div")
div.id = "fixtures"
document.body.appendChild div
return div

run_with_fixtures = (targets..., callback) ->
xml_http = new XMLHttpRequest()
responses = []
for target in targets
xml_http.open("GET", "spec/fixtures/#{target}", false)
xml_http.send()
responses.push xml_http.responseText
div_for_fixtures().innerHTML = responses.join("\n")

callback.call()

clear_fixtures()
3 changes: 2 additions & 1 deletion spec/coffee/post_spec.coffee
@@ -1,3 +1,4 @@
describe "The truth", ->
it "should be true", ->
expect(true).toBeTruthy()
run_with_fixtures "test.html", ->
expect(true).toBeTruthy()

0 comments on commit 55d2470

Please sign in to comment.