jasmine 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Rakefile +11 -2
  2. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +2 -2
  3. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +2 -1
  4. data/jasmine.gemspec +1 -1
  5. data/lib/jasmine.rb +10 -2
  6. data/lib/jasmine/application.rb +6 -33
  7. data/lib/jasmine/asset_expander.rb +19 -0
  8. data/lib/jasmine/asset_pipeline_mapper.rb +11 -14
  9. data/lib/jasmine/asset_pipeline_utility.rb +19 -0
  10. data/lib/jasmine/base.rb +4 -0
  11. data/lib/jasmine/config.rb +74 -111
  12. data/lib/jasmine/configuration.rb +83 -0
  13. data/lib/jasmine/core_configuration.rb +28 -0
  14. data/lib/jasmine/javascripts/boot.js +28 -0
  15. data/lib/jasmine/path_expander.rb +18 -0
  16. data/lib/jasmine/path_mapper.rb +29 -0
  17. data/lib/jasmine/results_processor.rb +21 -20
  18. data/lib/jasmine/run.html.erb +0 -37
  19. data/lib/jasmine/run_specs.rb +12 -8
  20. data/lib/jasmine/server.rb +1 -1
  21. data/lib/jasmine/tasks/jasmine.rake +3 -4
  22. data/lib/jasmine/version.rb +1 -1
  23. data/lib/jasmine/yaml_config_parser.rb +54 -0
  24. data/spec/application_integration_spec.rb +15 -0
  25. data/spec/application_spec.rb +37 -92
  26. data/spec/asset_expander_spec.rb +42 -0
  27. data/spec/asset_pipeline_mapper_spec.rb +12 -11
  28. data/spec/base_spec.rb +14 -0
  29. data/spec/configuration_spec.rb +163 -0
  30. data/spec/jasmine_self_test_spec.rb +14 -7
  31. data/spec/page_spec.rb +2 -4
  32. data/spec/path_expander_spec.rb +96 -0
  33. data/spec/path_mapper_spec.rb +33 -0
  34. data/spec/server_spec.rb +2 -2
  35. data/spec/yaml_config_parser_spec.rb +182 -0
  36. metadata +34 -23
  37. data/lib/jasmine/runner_config.rb +0 -71
  38. data/lib/jasmine/sprockets_mapper.rb +0 -13
  39. data/lib/rack/jasmine/redirect.rb +0 -20
  40. data/spec/config_spec.rb +0 -309
  41. data/spec/fixture/jasmine.erb.yml +0 -4
  42. data/spec/fixture/spec/example_spec.js +0 -5
  43. data/spec/fixture/src/example.js +0 -3
  44. data/spec/jasmine_self_test_config.rb +0 -19
  45. data/spec/runner_config_spec.rb +0 -136
  46. data/spec/sprockets_mapper_spec.rb +0 -17
@@ -0,0 +1,28 @@
1
+ module Jasmine
2
+ class CoreConfiguration
3
+ def initialize(core = Jasmine::Core)
4
+ @core = core
5
+ end
6
+
7
+ def path
8
+ @core.path
9
+ end
10
+
11
+ #TODO: maybe this doesn't belong in CoreConfig
12
+ def boot_path
13
+ Jasmine.root('javascripts')
14
+ end
15
+
16
+ def boot_files
17
+ Dir.glob(File.join(boot_path, "**"))
18
+ end
19
+
20
+ def js_files
21
+ @core.js_files
22
+ end
23
+
24
+ def css_files
25
+ @core.css_files
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ var jsApiReporter;
2
+ (function() {
3
+ var jasmineEnv = jasmine.getEnv();
4
+
5
+ jsApiReporter = new jasmine.JsApiReporter();
6
+ var htmlReporter = new jasmine.HtmlReporter();
7
+
8
+ jasmineEnv.addReporter(jsApiReporter);
9
+ jasmineEnv.addReporter(htmlReporter);
10
+
11
+ jasmineEnv.specFilter = function(spec) {
12
+ return htmlReporter.specFilter(spec);
13
+ };
14
+
15
+ var currentWindowOnload = window.onload;
16
+
17
+ window.onload = function() {
18
+ if (currentWindowOnload) {
19
+ currentWindowOnload();
20
+ }
21
+ execJasmine();
22
+ };
23
+
24
+ function execJasmine() {
25
+ jasmineEnv.execute();
26
+ }
27
+
28
+ })();
@@ -0,0 +1,18 @@
1
+ module Jasmine
2
+ class PathExpander
3
+
4
+ def self.expand(base_directory, patterns, globber = Dir.method(:glob))
5
+ negative, positive = patterns.partition {|pattern| /^!/ =~ pattern}
6
+ chosen, negated = [positive, negative].collect do |patterns|
7
+ patterns.map do |path|
8
+ files = globber.call(File.join(base_directory, path.gsub(/^!/, '')))
9
+ if files.empty? && !(path =~ /\*|^\!/)
10
+ files = [File.join(base_directory, path)]
11
+ end
12
+ files
13
+ end.flatten.uniq
14
+ end
15
+ chosen - negated
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Jasmine
2
+ class PathMapper
3
+ def initialize(config)
4
+ @config = config
5
+ end
6
+
7
+ def map_src_paths(paths)
8
+ map(paths, @config.src_dir, @config.src_path)
9
+ end
10
+
11
+ def map_spec_paths(paths)
12
+ map(paths, @config.spec_dir, @config.spec_path)
13
+ end
14
+
15
+ def map_boot_paths(paths)
16
+ map(paths, @config.boot_dir, @config.boot_path)
17
+ end
18
+
19
+ def map_jasmine_paths(paths)
20
+ map(paths, @config.jasmine_dir, @config.jasmine_path)
21
+ end
22
+
23
+ private
24
+ def map(paths, remove_path, add_path)
25
+ paths.map { |path| File.join(add_path, (path.gsub(remove_path, ''))) }
26
+ end
27
+
28
+ end
29
+ end
@@ -10,27 +10,28 @@ module Jasmine
10
10
  end
11
11
 
12
12
  def example_locations
13
- example_locations = {}
14
- example_name_parts = []
15
- previous_indent_level = 0
16
- @config.spec_files_full_paths.each do |filename|
17
- line_number = 1
18
- File.open(filename, "r") do |file|
19
- file.readlines.each do |line|
20
- match = /^(\s*)(describe|it)\s*\(\s*["'](.*)["']\s*,\s*function/.match(line)
21
- if (match)
22
- indent_level = match[1].length / 2
23
- example_name = match[3]
24
- example_name_parts[indent_level] = example_name
13
+ # example_locations = {}
14
+ # example_name_parts = []
15
+ # previous_indent_level = 0
16
+ # @config.spec_files_full_paths.each do |filename|
17
+ # line_number = 1
18
+ # File.open(filename, "r") do |file|
19
+ # file.readlines.each do |line|
20
+ # match = /^(\s*)(describe|it)\s*\(\s*["'](.*)["']\s*,\s*function/.match(line)
21
+ # if (match)
22
+ # indent_level = match[1].length / 2
23
+ # example_name = match[3]
24
+ # example_name_parts[indent_level] = example_name
25
25
 
26
- full_example_name = example_name_parts.slice(0, indent_level + 1).join(" ")
27
- example_locations[full_example_name] = "#{filename}:#{line_number}: in `it'"
28
- end
29
- line_number += 1
30
- end
31
- end
32
- end
33
- example_locations
26
+ # full_example_name = example_name_parts.slice(0, indent_level + 1).join(" ")
27
+ # example_locations[full_example_name] = "#{filename}:#{line_number}: in `it'"
28
+ # end
29
+ # line_number += 1
30
+ # end
31
+ # end
32
+ # end
33
+ # example_locations
34
+ {}
34
35
  end
35
36
 
36
37
  end
@@ -7,43 +7,6 @@
7
7
  <% css_files.each do |css_file| %>
8
8
  <link rel="stylesheet" href="<%= css_file %>" type="text/css" media="screen"/>
9
9
  <% end %>
10
-
11
- <% jasmine_files.each do |jasmine_file| %>
12
- <script src="<%= jasmine_file %>" type="text/javascript"></script>
13
- <% end %>
14
-
15
- <script type="text/javascript">
16
- //TODO: make this a js file that gets passed in, then iterate over only js_files
17
- var jsApiReporter;
18
- (function() {
19
- var jasmineEnv = jasmine.getEnv();
20
-
21
- jsApiReporter = new jasmine.JsApiReporter();
22
- var htmlReporter = new jasmine.HtmlReporter();
23
-
24
- jasmineEnv.addReporter(jsApiReporter);
25
- jasmineEnv.addReporter(htmlReporter);
26
-
27
- jasmineEnv.specFilter = function(spec) {
28
- return htmlReporter.specFilter(spec);
29
- };
30
-
31
- var currentWindowOnload = window.onload;
32
-
33
- window.onload = function() {
34
- if (currentWindowOnload) {
35
- currentWindowOnload();
36
- }
37
- execJasmine();
38
- };
39
-
40
- function execJasmine() {
41
- jasmineEnv.execute();
42
- }
43
-
44
- })();
45
- </script>
46
-
47
10
  <% js_files.each do |js_file| %>
48
11
  <script src="<%= js_file %>" type="text/javascript"></script>
49
12
  <% end %>
@@ -2,18 +2,22 @@ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing
2
2
 
3
3
  require 'rubygems'
4
4
  require 'jasmine'
5
- jasmine_config_overrides = File.expand_path(File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine_config.rb'))
6
- require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
7
5
  if Jasmine::Dependencies.rspec2?
8
6
  require 'rspec'
9
7
  else
10
8
  require 'spec'
11
9
  end
12
10
 
13
- jasmine_runner_config = Jasmine::RunnerConfig.new
14
- server = Jasmine::Server.new(jasmine_runner_config.port, Jasmine::Application.app(jasmine_runner_config))
15
- client = Jasmine::SeleniumDriver.new(jasmine_runner_config.browser, jasmine_runner_config.jasmine_server_url)
11
+ jasmine_yml = File.join(Dir.pwd, 'spec', 'javascripts', 'support', 'jasmine.yml')
12
+ if File.exist?(jasmine_yml)
13
+ end
14
+
15
+ Jasmine.load_configuration_from_yaml
16
+
17
+ config = Jasmine.config
16
18
 
19
+ server = Jasmine::Server.new(config.port, Jasmine::Application.app(config))
20
+ driver = Jasmine::SeleniumDriver.new(config.browser, "#{config.host}:#{config.port}/")
17
21
  t = Thread.new do
18
22
  begin
19
23
  server.start
@@ -22,11 +26,11 @@ t = Thread.new do
22
26
  # # ignore bad exits
23
27
  end
24
28
  t.abort_on_exception = true
25
- Jasmine::wait_for_listener(jasmine_runner_config.port, "jasmine server")
29
+ Jasmine::wait_for_listener(config.port, "jasmine server")
26
30
  puts "jasmine server started."
27
31
 
28
- results_processor = Jasmine::ResultsProcessor.new(jasmine_runner_config)
29
- results = Jasmine::Runners::HTTP.new(client, results_processor, jasmine_runner_config.result_batch_size).run
32
+ results_processor = Jasmine::ResultsProcessor.new(config)
33
+ results = Jasmine::Runners::HTTP.new(driver, results_processor, config.result_batch_size).run
30
34
  formatter = Jasmine::RspecFormatter.new
31
35
  formatter.format_results(results)
32
36
 
@@ -1,6 +1,6 @@
1
1
  module Jasmine
2
2
  class Server
3
- def initialize(port = 8888, application = Jasmine::Application.app)
3
+ def initialize(port = 8888, application = nil)
4
4
  @port = port
5
5
  @application = application
6
6
  end
@@ -42,13 +42,12 @@ namespace :jasmine do
42
42
  end
43
43
 
44
44
  task :server => "jasmine:require" do
45
- jasmine_config_overrides = File.join(Jasmine::Config.new.project_root, 'spec', 'javascripts' ,'support' ,'jasmine_config.rb')
46
- require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
47
-
48
45
  port = ENV['JASMINE_PORT'] || 8888
49
46
  puts "your tests are here:"
50
47
  puts " http://localhost:#{port}/"
51
- Jasmine::Server.new(port).start
48
+ Jasmine.load_configuration_from_yaml
49
+ app = Jasmine::Application.app(Jasmine.config)
50
+ Jasmine::Server.new(port, app).start
52
51
  end
53
52
  end
54
53
 
@@ -1,3 +1,3 @@
1
1
  module Jasmine
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -0,0 +1,54 @@
1
+ module Jasmine
2
+ class YamlConfigParser
3
+ def initialize(path, pwd, path_expander = lambda {}, yaml_loader = lambda {})
4
+ @path = path
5
+ @path_expander = path_expander
6
+ @pwd = pwd
7
+ @yaml_loader = yaml_loader
8
+ end
9
+
10
+ def src_dir
11
+ return @pwd unless loaded_yaml['src_dir']
12
+ File.join(@pwd, loaded_yaml['src_dir'])
13
+ end
14
+
15
+ def spec_dir
16
+ return File.join(@pwd, 'spec', 'javascripts') unless loaded_yaml['spec_dir']
17
+ File.join(@pwd, loaded_yaml['spec_dir'])
18
+ end
19
+
20
+ def jasmine_dir
21
+ return nil unless loaded_yaml['jasmine_dir']
22
+ File.join(@pwd, loaded_yaml['jasmine_dir'])
23
+ end
24
+
25
+ def src_files
26
+ @path_expander.call(src_dir, loaded_yaml['src_files'] || [])
27
+ end
28
+
29
+ def jasmine_files
30
+ @path_expander.call(jasmine_dir, loaded_yaml['jasmine_files'] || [])
31
+ end
32
+
33
+ def jasmine_css_files
34
+ @path_expander.call(jasmine_dir, loaded_yaml['jasmine_css_files'] || [])
35
+ end
36
+
37
+ def spec_files
38
+ @path_expander.call(spec_dir, loaded_yaml['spec_files'] || [])
39
+ end
40
+
41
+ def helpers
42
+ @path_expander.call(spec_dir, loaded_yaml['helpers'] || [])
43
+ end
44
+
45
+ def css_files
46
+ @path_expander.call(src_dir, loaded_yaml['stylesheets'] || [])
47
+ end
48
+
49
+ private
50
+ def loaded_yaml
51
+ @yaml_loader.call(@path)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Jasmine::Application" do
4
+
5
+ it "includes no-cache headers for specs" do
6
+ pending
7
+ get "/__spec__/example_spec.js"
8
+ last_response.headers.should have_key("Cache-Control")
9
+ last_response.headers["Cache-Control"].should == "max-age=0, private, must-revalidate"
10
+ last_response.headers['Pragma'].each do |key|
11
+ last_response.headers[key].should == 'no-cache'
12
+ end
13
+ end
14
+
15
+ end
@@ -1,99 +1,44 @@
1
1
  require 'spec_helper'
2
- require 'rack/test'
3
2
 
4
- describe "Jasmine::Application" do
5
- include Rack::Test::Methods
6
-
7
- def app
8
- @root = File.join(File.dirname(__FILE__))
9
- runner_config = double("config",
10
- :project_root => @root,
11
- :spec_dir => File.join(@root, "fixture", "spec"),
12
- :spec_path => "/__spec__",
13
- :root_path => "/__root__",
14
- :css_files => [],
15
- :jasmine_files => [],
16
- :js_files => ["path/file1.js", "path/file2.js"],
17
- :src_dir => File.join(@root, "fixture", "src"),
18
- :src_files => ["file1.js"],
19
- :spec_files => ["example_spec.js"])
20
- Jasmine::Application.app(runner_config)
21
- end
22
-
23
- it "includes no-cache headers for specs" do
24
- get "/__spec__/example_spec.js"
25
- last_response.headers.should have_key("Cache-Control")
26
- last_response.headers["Cache-Control"].should == "max-age=0, private, must-revalidate"
27
- end
28
-
29
- it "should serve static files from spec dir under __spec__" do
30
- get "/__spec__/example_spec.js"
31
- last_response.status.should == 200
32
- last_response.content_type.should == "application/javascript"
33
- last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js"))
34
- end
35
-
36
- it "should serve static files from root dir under __root__" do
37
- get "/__root__/fixture/src/example.js"
38
- last_response.status.should == 200
39
- last_response.content_type.should == "application/javascript"
40
- last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
41
- end
42
-
43
- it "should serve static files from src dir under /" do
44
- get "/example.js"
45
- last_response.status.should == 200
46
- last_response.content_type.should == "application/javascript"
47
- last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
48
- end
49
-
50
- it "should serve Jasmine static files under /__JASMINE_ROOT__/" do
51
- get "/__JASMINE_ROOT__/jasmine.css"
52
- last_response.status.should == 200
53
- last_response.content_type.should == "text/css"
54
- last_response.body.should == File.read(File.join(Jasmine::Core.path, "jasmine.css"))
55
- end
56
-
57
- it "should serve focused suites when prefixing spec files with /__suite__/" do
58
- pending "Temporarily removing this feature (maybe permanent)"
59
- Dir.stub!(:glob).and_return { |glob_string| [glob_string] }
60
- get "/__suite__/file2.js"
61
- last_response.status.should == 200
62
- last_response.content_type.should == "text/html"
63
- last_response.body.should include("\"/__spec__/file2.js")
64
- end
65
-
66
- it "should redirect /run.html to /" do
67
- get "/run.html"
68
- last_response.status.should == 302
69
- last_response.location.should == "/"
70
- end
71
-
72
- it "should 404 non-existent files" do
73
- get "/some-non-existent-file"
74
- last_response.should be_not_found
75
- end
76
-
77
- describe "/ page" do
78
- it "should load each js file in order" do
79
- get "/"
80
- last_response.status.should == 200
81
- last_response.body.should include("path/file1.js")
82
- last_response.body.should include("path/file2.js")
83
- end
3
+ #Rspec 1 doesn't correctly pass blocks to stubs, so skip (covered by integration tests)
4
+ #https://groups.google.com/forum/?fromgroups=#!topic/rspec/XT7paH2asCo
5
+
6
+ if Jasmine::Dependencies.rspec2?
7
+ describe "Jasmine::Application" do
8
+ it "should map paths provided by the config" do
9
+ handler1 = double(:handler1)
10
+ handler2 = double(:handler2)
11
+ app1 = double(:app1)
12
+ app2 = double(:app2)
13
+ rack_path_map = {"/foo" => lambda { handler1 }, "/bar" => lambda { handler2 }}
14
+ config = double(:config, :rack_path_map => rack_path_map, :rack_apps => [])
15
+ builder = double("Rack::Builder.new")
16
+ #Rack::Builder instance evals, so builder.run is invalid syntax,
17
+ #this is the only way to stub out the 'run' dsl it gives to the block.
18
+ Jasmine::Application.stub(:run).with(handler1).and_return(app1)
19
+ Jasmine::Application.stub(:run).with(handler2).and_return(app2)
20
+
21
+ builder.should_receive(:map).twice do |path, &app|
22
+ if path == '/foo'
23
+ app.call.should == app1
24
+ elsif path == '/bar'
25
+ app.call.should == app2
26
+ else
27
+ raise "Unexpected path passed"
28
+ end
29
+ end
84
30
 
85
- it "should return an empty 200 for HEAD requests to /" do
86
- head "/"
87
- last_response.status.should == 200
88
- last_response.headers['Content-Type'].should == 'text/html'
89
- last_response.body.should == ''
31
+ Jasmine::Application.app(config, builder).should == builder
90
32
  end
91
-
92
- it "should tell the browser not to cache any assets" do
93
- head "/"
94
- ['Pragma'].each do |key|
95
- last_response.headers[key].should == 'no-cache'
96
- end
33
+ it "should run rack apps provided by the config" do
34
+ app1 = double(:app1)
35
+ app2 = double(:app2)
36
+ block = lambda { "foo" }
37
+ config = double(:config, :rack_path_map => [], :rack_apps => [[app1, nil], [app2, block]])
38
+ builder = double("Rack::Builder.new")
39
+ builder.should_receive(:use).with(app1)
40
+ builder.should_receive(:use).with(app2, &block)
41
+ Jasmine::Application.app(config, builder).should == builder
97
42
  end
98
43
  end
99
44
  end