Skip to content

Commit

Permalink
Restore runner_config_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
ragaskar committed Jul 14, 2012
1 parent 6bdc500 commit d5aa623
Showing 1 changed file with 65 additions and 235 deletions.
300 changes: 65 additions & 235 deletions spec/runner_config_spec.rb
@@ -1,257 +1,87 @@
require 'spec_helper'
require 'selenium-webdriver'

describe Jasmine::Config do
describe "configuration" do
before :each do
temp_dir_before

Dir::chdir @tmp
dir_name = "test_js_project"
`mkdir -p #{dir_name}`
Dir::chdir dir_name
`#{@root}/bin/jasmine init .`

@project_dir = Dir.pwd

@template_dir = File.expand_path(File.join(@root, "generators/jasmine/templates"))
@config = Jasmine::Config.new
describe Jasmine::RunnerConfig do
describe "css_files" do
it "should return the jasmine stylesheets and any user defined stylesheets" do
jasmine_stylesheets = ['some/css/file']
user_stylesheets = ['some/user/file']
user_config = double("config", :jasmine_stylesheets => jasmine_stylesheets, :user_stylesheets => user_stylesheets)
Jasmine::RunnerConfig.new(user_config).css_files.should == jasmine_stylesheets + user_stylesheets
end
end

after(:each) do
temp_dir_after
describe "jasmine_files" do
it "should return the jasmine files from the config" do
jasmine_files = ['some/file']
user_config = double('config', :jasmine_javascripts => jasmine_files)
Jasmine::RunnerConfig.new(user_config).jasmine_files.should == jasmine_files
end
end

describe "defaults" do
it "src_dir uses root when src dir is blank" do
@config.stub!(:project_root).and_return('some_project_root')
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
YAML.stub!(:load).and_return({'src_dir' => nil})
@config.src_dir.should == 'some_project_root'
end

it "should use correct default yaml config" do
@config.stub!(:project_root).and_return('some_project_root')
@config.simple_config_file.should == (File.join('some_project_root', 'spec/javascripts/support/jasmine.yml'))
end
describe "js_files" do
it "should return the user js files from the config" do
js_files = ['some/file']
user_config = double('config', :js_files => js_files)
Jasmine::RunnerConfig.new(user_config).js_files.should == js_files
end
end

describe "simple_config" do
before(:each) do
@config.stub!(:src_dir).and_return(File.join(@project_dir, "."))
@config.stub!(:spec_dir).and_return(File.join(@project_dir, "spec/javascripts"))
end

describe "using default jasmine.yml" do
before(:each) do
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
end

it "should find the source files" do
@config.src_files.should =~ ['public/javascripts/Player.js', 'public/javascripts/Song.js']
end

it "should find the stylesheet files" do
@config.stylesheets.should == []
end

it "should find the spec files" do
@config.spec_files.should == ['PlayerSpec.js']
end

it "should find any helpers" do
@config.helpers.should == ['helpers/SpecHelper.js']
end

it "should build an array of all the JavaScript files to include, source files then spec files" do
@config.js_files.should == [
'/public/javascripts/Player.js',
'/public/javascripts/Song.js',
'/__spec__/helpers/SpecHelper.js',
'/__spec__/PlayerSpec.js'
]
end

it "should allow the js_files to be filtered" do
@config.js_files("PlayerSpec.js").should == [
'/public/javascripts/Player.js',
'/public/javascripts/Song.js',
'/__spec__/helpers/SpecHelper.js',
'/__spec__/PlayerSpec.js'
]
end

it "should report the full paths of the spec files" do
@config.spec_files_full_paths.should == [File.join(@project_dir, 'spec/javascripts/PlayerSpec.js')]
end
end

it "should parse ERB" do
@config.stub!(:simple_config_file).and_return(File.expand_path(File.join(@root, 'spec', 'fixture','jasmine.erb.yml')))
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
@config.src_files.should == ['file0.js', 'file1.js', 'file2.js',]
end

describe "if jasmine.yml not found" do
before(:each) do
File.stub!(:exist?).and_return(false)
end

it "should default to loading no source files" do
@config.src_files.should be_empty
end

it "should default to loading no stylesheet files" do
@config.stylesheets.should be_empty
end

end

describe "if jasmine.yml is empty" do
before(:each) do
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))
YAML.stub!(:load).and_return(false)
end

it "should default to loading no source files" do
@config.src_files.should be_empty
end

it "should default to loading no stylesheet files" do
@config.stylesheets.should be_empty
end
end

describe "should use the first appearance of duplicate filenames" do
before(:each) do
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "file2.ext", "file1.ext"] }
@config.stub!(:simple_config).and_return(fake_config)
end

it "src_files" do
@config.src_files.should == ['file1.ext', 'file2.ext']
end

it "stylesheets" do
@config.stylesheets.should == ['file1.ext', 'file2.ext']
end

it "spec_files" do
@config.spec_files.should == ['file1.ext', 'file2.ext']
end

it "helpers" do
@config.spec_files.should == ['file1.ext', 'file2.ext']
end

it "js_files" do
@config.js_files.should == ["/file1.ext",
"/file2.ext",
"/__spec__/file1.ext",
"/__spec__/file2.ext",
"/__spec__/file1.ext",
"/__spec__/file2.ext"]
end

it "spec_files_full_paths" do
@config.spec_files_full_paths.should == [
File.expand_path("spec/javascripts/file1.ext", @project_dir),
File.expand_path("spec/javascripts/file2.ext", @project_dir)
]
end
end

describe "should permit explicity-declared filenames to pass through regardless of their existence" do
before(:each) do
Dir.stub!(:glob).and_return { |glob_string| [] }
fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "!file2.ext", "**/*file3.ext"] }
@config.stub!(:simple_config).and_return(fake_config)
end

it "should contain explicitly files" do
@config.src_files.should == ["file1.ext"]
end
end

describe "should allow .gitignore style negation (!pattern)" do
before(:each) do
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
fake_config = Hash.new.stub!(:[]).and_return { |x| ["file1.ext", "!file1.ext", "file2.ext"] }
@config.stub!(:simple_config).and_return(fake_config)
end

it "should not contain negated files" do
@config.src_files.should == ["file2.ext"]
end
end

it "simple_config stylesheets" do
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yml'))

YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
Dir.stub!(:glob).and_return { |glob_string| [glob_string] }

@config.stylesheets.should == ['foo.css', 'bar.css']
end
describe "spec_files" do
it "should return the user spec_files from the config" do
spec_files = ['some/file']
user_config = double('config', :spec_files => spec_files)
Jasmine::RunnerConfig.new(user_config).spec_files.should == spec_files
end
end

it "using rails jasmine.yml" do
['public/javascripts/prototype.js',
'public/javascripts/effects.js',
'public/javascripts/controls.js',
'public/javascripts/dragdrop.js',
'public/javascripts/application.js'].each { |f| `touch #{f}` }
describe "spec_files_full_paths" do
it "should return the user spec_files_full_paths from the config" do
spec_files_full_paths = ['some/file_path']
user_config = double('config', :spec_files_full_paths => spec_files_full_paths)
Jasmine::RunnerConfig.new(user_config).spec_files_full_paths.should == spec_files_full_paths
end
end

@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
describe "spec_path" do
it "should return the user spec_path from the config" do
spec_path = ['some/path']
user_config = double('config', :spec_path => spec_path)
Jasmine::RunnerConfig.new(user_config).spec_path.should == spec_path
end
end

@config.spec_files.should == ['PlayerSpec.js']
@config.helpers.should == ['helpers/SpecHelper.js']
@config.src_files.should == ['public/javascripts/prototype.js',
'public/javascripts/effects.js',
'public/javascripts/controls.js',
'public/javascripts/dragdrop.js',
'public/javascripts/application.js',
'public/javascripts/Player.js',
'public/javascripts/Song.js']
@config.js_files.should == [
'/public/javascripts/prototype.js',
'/public/javascripts/effects.js',
'/public/javascripts/controls.js',
'/public/javascripts/dragdrop.js',
'/public/javascripts/application.js',
'/public/javascripts/Player.js',
'/public/javascripts/Song.js',
'/__spec__/helpers/SpecHelper.js',
'/__spec__/PlayerSpec.js',
]
@config.js_files("PlayerSpec.js").should == [
'/public/javascripts/prototype.js',
'/public/javascripts/effects.js',
'/public/javascripts/controls.js',
'/public/javascripts/dragdrop.js',
'/public/javascripts/application.js',
'/public/javascripts/Player.js',
'/public/javascripts/Song.js',
'/__spec__/helpers/SpecHelper.js',
'/__spec__/PlayerSpec.js'
]
end
describe "spec_dir" do
it "should return the user spec_dir from the config" do
spec_dir = ['some/dir']
user_config = double('config', :spec_dir => spec_dir)
Jasmine::RunnerConfig.new(user_config).spec_dir.should == spec_dir
end
end

describe "src_dir" do
it "should return the user src_dir from the config" do
src_dir = ['some/dir']
user_config = double('config', :src_dir => src_dir)
Jasmine::RunnerConfig.new(user_config).src_dir.should == src_dir
end
end

describe "jasmine_stylesheets" do
it "should return the relative web server path to the core Jasmine css stylesheets" do
#TODO: wrap Jasmine::Core with a class that knows about the core path and the relative mapping.
Jasmine::Core.stub(:css_files).and_return(["my_css_file1.css", "my_css_file2.css"])
Jasmine::Config.new.jasmine_stylesheets.should == ["/__JASMINE_ROOT__/my_css_file1.css", "/__JASMINE_ROOT__/my_css_file2.css"]
describe "project_root" do
it "should return the user project_root from the config" do
project_root = ['some/dir']
user_config = double('config', :project_root => project_root)
Jasmine::RunnerConfig.new(user_config).project_root.should == project_root
end
end

describe "jasmine_javascripts" do
it "should return the relative web server path to the core Jasmine css javascripts" do
Jasmine::Core.stub(:js_files).and_return(["my_js_file1.js", "my_js_file2.js"])
Jasmine::Config.new.jasmine_javascripts.should == ["/__JASMINE_ROOT__/my_js_file1.js", "/__JASMINE_ROOT__/my_js_file2.js"]
describe "root_path" do
it "should return the user root_path from the config" do
root_path = ['some/path']
user_config = double('config', :root_path => root_path)
Jasmine::RunnerConfig.new(user_config).root_path.should == root_path
end
end

end

0 comments on commit d5aa623

Please sign in to comment.