jasmine 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::AssetExpander do
4
+ it "expands asset files" do
5
+ bundled_asset = double(:bundled_asset,
6
+ :to_a => ['asset1', 'asset2'],
7
+ :pathname => double(:pathname, :to_s => '/some_src_dir/asset_file'))
8
+
9
+ bundled_asset_getter = lambda do |filepath, ext|
10
+ if filepath == 'asset_file' && ext == 'js'
11
+ bundled_asset
12
+ end
13
+ end
14
+
15
+ asset_path_getter = lambda do |asset|
16
+ if asset == 'asset1'
17
+ 'asset1_path'
18
+ elsif asset == 'asset2'
19
+ 'asset2_path'
20
+ end
21
+ end
22
+
23
+ expander = Jasmine::AssetExpander.new(bundled_asset_getter, asset_path_getter)
24
+ expanded_assets = expander.expand('/some_src_dir', 'asset_file')
25
+ expanded_assets.should == ['/asset_file?body=true',
26
+ '/asset1_path?body=true',
27
+ '/asset2_path?body=true']
28
+ end
29
+
30
+ it "return nil if no bundled asset is found" do
31
+ bundled_asset = nil
32
+ bundled_asset_getter = lambda do |filepath, ext|
33
+ if filepath == 'asset_file' && ext == 'js'
34
+ bundled_asset
35
+ end
36
+ end
37
+
38
+ expander = Jasmine::AssetExpander.new(bundled_asset_getter, lambda {})
39
+ expanded_assets = expander.expand('/some_src_dir', 'asset_file')
40
+ expanded_assets.should be_nil
41
+ end
42
+ end
@@ -1,18 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Jasmine::AssetPipelineMapper do
4
- describe "mapping files" do
5
- it "should retrieve asset paths from the asset pipeline for passed files" do
6
- #TODO: this expects all src files to be asset pipeline files
7
- src_files = ["assets/application.js", "assets/other_manifest.js"]
8
- asset_context = double("asset context")
9
- asset_context.stub_chain(:asset_paths, :asset_for).with("application", "js").and_return(['asset1.js', 'asset2.js'])
10
- asset_context.stub_chain(:asset_paths, :asset_for).with("other_manifest", "js").and_return(['asset1.js', 'asset3.js'])
11
- asset_context.stub(:asset_path) do |asset|
12
- "/some_location/#{asset}"
4
+ it "expands asset paths if available" do
5
+ expander = lambda do |dir, path|
6
+ if dir == "/some_location/" && path == 'asset1'
7
+ ['asset1', 'asset2']
8
+ elsif dir == "/some_location/" && path == 'asset2'
9
+ ['asset1', 'asset3']
13
10
  end
14
- mapper = Jasmine::AssetPipelineMapper.new(asset_context)
15
- mapper.files(src_files).should == ['some_location/asset1.js?body=true', 'some_location/asset2.js?body=true', 'some_location/asset3.js?body=true']
11
+
16
12
  end
13
+ config = double(:config, :src_dir => "/some_location/")
14
+
15
+ mapper = Jasmine::AssetPipelineMapper.new(config, expander)
16
+
17
+ mapper.map_src_paths(['asset1', 'asset2', 'asset4']).should == ['asset1', 'asset2', 'asset3', 'asset4']
17
18
  end
18
19
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine do
4
+ it "should provide the root path" do
5
+ File.stub(:dirname).and_return('lib/jasmine')
6
+ File.should_receive(:expand_path) { |path| path }
7
+ Jasmine.root.should == 'lib/jasmine'
8
+ end
9
+ it "should append passed file paths" do
10
+ File.stub(:dirname).and_return('lib/jasmine')
11
+ File.should_receive(:expand_path) { |path| path }
12
+ Jasmine.root('subdir1', 'subdir2').should == File.join('lib/jasmine', 'subdir1', 'subdir2')
13
+ end
14
+ end
@@ -0,0 +1,163 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::Configuration do
4
+ let(:test_mapper1) do
5
+ Class.new do
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+ def map_src_paths(paths)
10
+ paths.map { |f| "mapped_src/#{f}" }
11
+ end
12
+ def map_jasmine_paths(paths)
13
+ paths.map { |f| "mapped_jasmine/#{f}" }
14
+ end
15
+ def map_spec_paths(paths)
16
+ paths.map { |f| "mapped_spec/#{f}" }
17
+ end
18
+ def map_boot_paths(paths)
19
+ paths.map { |f| "mapped_boot/#{f}" }
20
+ end
21
+ end
22
+ end
23
+ let(:test_mapper2) do
24
+ Class.new do
25
+ def initialize(config)
26
+ @config = config
27
+ end
28
+ def map_src_paths(paths)
29
+ paths.map { |f| "#{f}/src" }
30
+ end
31
+ def map_jasmine_paths(paths)
32
+ paths.map { |f| "#{f}/jasmine" }
33
+ end
34
+ def map_spec_paths(paths)
35
+ paths.map { |f| "#{f}/spec" }
36
+ end
37
+ def map_boot_paths(paths)
38
+ paths.map { |f| "#{f}/boot" }
39
+ end
40
+ end
41
+ end
42
+ let(:test_mapper3) do
43
+ Class.new do
44
+ def initialize(config)
45
+ @config = config
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "returning css files" do
51
+ it "returns mapped jasmine_css_files + css_files" do
52
+ config = Jasmine::Configuration.new()
53
+ config.add_path_mapper(lambda { |c| test_mapper1.new(c) })
54
+ config.add_path_mapper(lambda { |c| test_mapper2.new(c) })
55
+ config.add_path_mapper(lambda { |c| test_mapper3.new(c) })
56
+ config.css_files.should == []
57
+ config.jasmine_css_files = lambda { ["jasmine_css"] }
58
+ config.css_files = lambda { ["css"] }
59
+ config.css_files.should == ['mapped_jasmine/jasmine_css/jasmine', 'mapped_src/css/src']
60
+ end
61
+ end
62
+
63
+ describe "returning javascript files" do
64
+ it "returns the jasmine core files, then srcs, then specs, then boot" do
65
+ config = Jasmine::Configuration.new()
66
+ config.add_path_mapper(lambda { |c| test_mapper1.new(c) })
67
+ config.add_path_mapper(lambda { |c| test_mapper2.new(c) })
68
+ config.add_path_mapper(lambda { |c| test_mapper3.new(c) })
69
+ config.js_files.should == []
70
+ config.jasmine_files = lambda { ['jasmine'] }
71
+ config.src_files = lambda { ['src'] }
72
+ config.boot_files = lambda { ['boot'] }
73
+ config.spec_files = lambda { ['spec'] }
74
+ config.js_files.should == [
75
+ 'mapped_jasmine/jasmine/jasmine',
76
+ 'mapped_src/src/src',
77
+ 'mapped_spec/spec/spec',
78
+ 'mapped_boot/boot/boot',
79
+ ]
80
+ end
81
+ end
82
+
83
+ describe "returning rack map" do
84
+ it "permits arbitrary rack app path mapping" do
85
+ config = Jasmine::Configuration.new()
86
+ result = double
87
+ config.add_rack_path('some/path', lambda { result })
88
+ map = config.rack_path_map
89
+ map['some/path'].should be
90
+ map['some/path'].call.should == result
91
+ end
92
+
93
+ end
94
+
95
+ describe "rack apps" do
96
+ it "permits the addition of arbitary rack apps" do
97
+ config = Jasmine::Configuration.new()
98
+ app = double
99
+ config.add_rack_app(app)
100
+ config.rack_apps.should == [[app, nil]]
101
+ end
102
+ it "permits the addition of arbitary rack apps with arbitrary config" do
103
+ config = Jasmine::Configuration.new()
104
+ app = double
105
+ block = lambda { "foo" }
106
+ config.add_rack_app(app, &block)
107
+ config.rack_apps.should == [[app, block]]
108
+ end
109
+ end
110
+
111
+ describe "port" do
112
+ it "returns new port and caches return value" do
113
+ config = Jasmine::Configuration.new()
114
+ Jasmine.stub(:find_unused_port).and_return('1234')
115
+ config.port.should == '1234'
116
+ Jasmine.stub(:find_unused_port).and_return('4321')
117
+ config.port.should == '1234'
118
+ end
119
+ it "returns port if configured" do
120
+ config = Jasmine::Configuration.new()
121
+ config.port = '5678'
122
+ Jasmine.stub(:find_unused_port).and_return('1234')
123
+ config.port.should == '5678'
124
+ end
125
+ end
126
+
127
+ describe "browser" do
128
+ it "should default to firefox" do
129
+ Jasmine::Configuration.new().browser.should == 'firefox'
130
+ end
131
+
132
+ it "returns browser if set" do
133
+ config = Jasmine::Configuration.new()
134
+ config.browser = 'foo'
135
+ config.browser.should == 'foo'
136
+ end
137
+ end
138
+
139
+ describe "result_batch_size" do
140
+ it "should default to 50" do
141
+ Jasmine::Configuration.new().result_batch_size.should == 50
142
+ end
143
+
144
+ it "returns result_batch_size if set" do
145
+ config = Jasmine::Configuration.new()
146
+ config.result_batch_size = 25
147
+ config.result_batch_size.should == 25
148
+ end
149
+ end
150
+
151
+ describe "host" do
152
+ it "should default to localhost" do
153
+ Jasmine::Configuration.new().host.should == 'http://localhost'
154
+ end
155
+
156
+ it "returns host if set" do
157
+ config = Jasmine::Configuration.new()
158
+ config.host = 'foo'
159
+ config.host.should == 'foo'
160
+ end
161
+ end
162
+ end
163
+
@@ -1,9 +1,16 @@
1
1
  require 'spec_helper'
2
- require 'jasmine_self_test_config'
3
2
 
4
- jasmine_runner_config = Jasmine::RunnerConfig.new(JasmineSelfTestConfig.new)
5
- server = Jasmine::Server.new(jasmine_runner_config.port, Jasmine::Application.app(jasmine_runner_config))
6
- client = Jasmine::SeleniumDriver.new(jasmine_runner_config.browser, jasmine_runner_config.jasmine_server_url)
3
+ Jasmine.configure do |config|
4
+ root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ config.src_dir = File.join(root, 'src')
6
+ config.spec_dir = Jasmine::Core.path
7
+ config.spec_files = lambda { (Jasmine::Core.html_spec_files + Jasmine::Core.core_spec_files).map {|f| File.join(config.spec_dir, f) } }
8
+ end
9
+
10
+ config = Jasmine.config
11
+
12
+ server = Jasmine::Server.new(config.port, Jasmine::Application.app(config))
13
+ driver = Jasmine::SeleniumDriver.new(config.browser, "#{config.host}:#{config.port}/")
7
14
 
8
15
  t = Thread.new do
9
16
  begin
@@ -13,10 +20,10 @@ t = Thread.new do
13
20
  # # ignore bad exits
14
21
  end
15
22
  t.abort_on_exception = true
16
- Jasmine::wait_for_listener(jasmine_runner_config.port, "jasmine server")
23
+ Jasmine::wait_for_listener(config.port, "jasmine server")
17
24
  puts "jasmine server started."
18
25
 
19
- results_processor = Jasmine::ResultsProcessor.new(jasmine_runner_config)
20
- results = Jasmine::Runners::HTTP.new(client, results_processor, jasmine_runner_config.result_batch_size).run
26
+ results_processor = Jasmine::ResultsProcessor.new(config)
27
+ results = Jasmine::Runners::HTTP.new(driver, results_processor, config.result_batch_size).run
21
28
  formatter = Jasmine::RspecFormatter.new
22
29
  formatter.format_results(results)
@@ -6,15 +6,13 @@ describe Jasmine::Page do
6
6
  describe "#render" do
7
7
  subject { Nokogiri::HTML(page.render) }
8
8
  let(:fake_config) do
9
- OpenStruct.new(:js_files => ["file1.js", "file2.js"],
10
- :css_files => ["file1.css", "file2.css"],
11
- :jasmine_files => ["jasmine_file1.js", "jasmine_file2.js"])
9
+ OpenStruct.new(:js_files => ["file1.js", "file2.js"], :css_files => ["file1.css", "file2.css"])
12
10
  end
13
11
  let(:context) { fake_config }
14
12
  let(:page) { Jasmine::Page.new(context) }
15
13
  it "should render javascript files in the correct order" do
16
14
  js_files = subject.css("script")
17
- js_files.map { |file| file["src"] }.compact.should == ["jasmine_file1.js", "jasmine_file2.js", "file1.js", "file2.js"]
15
+ js_files.map { |file| file["src"] }.compact.should == ["file1.js", "file2.js"]
18
16
  end
19
17
 
20
18
  it "should render css files in the correct order" do
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::PathExpander do
4
+ it "returns absolute paths" do
5
+ dir_glob = lambda do |pattern|
6
+ case pattern
7
+ when 'some_base/src1*'
8
+ ['some_base/src1.js', 'some_base/src15.js']
9
+ when 'some_base/src2*'
10
+ ['some_base/src2.js']
11
+ else
12
+ raise "Unexpected pattern received: #{pattern}"
13
+ end
14
+ end
15
+
16
+ expanded_files = Jasmine::PathExpander.expand(
17
+ 'some_base',
18
+ ['src1*', 'src2*'],
19
+ dir_glob
20
+ )
21
+
22
+ expanded_files.should == [
23
+ File.join('some_base', 'src1.js'),
24
+ File.join('some_base', 'src15.js'),
25
+ File.join('some_base', 'src2.js')
26
+ ]
27
+ end
28
+
29
+ it "uniqs files" do
30
+ dir_glob = lambda do |pattern|
31
+ case pattern
32
+ when 'some_base/src1*'
33
+ ['some_base/src1.js', 'some_base/src15.js', 'some_base/src1.js']
34
+ when 'some_base/src2*'
35
+ ['some_base/src2.js']
36
+ else
37
+ raise "Unexpected pattern received: #{pattern}"
38
+ end
39
+ end
40
+
41
+ expanded_files = Jasmine::PathExpander.expand(
42
+ 'some_base',
43
+ ['src1*', 'src2*'],
44
+ dir_glob
45
+ )
46
+
47
+ expanded_files.should == [
48
+ File.join('some_base', 'src1.js'),
49
+ File.join('some_base', 'src15.js'),
50
+ File.join('some_base', 'src2.js')
51
+ ]
52
+ end
53
+
54
+ it "supports negation of passed patterns" do
55
+ dir_glob = lambda do |pattern|
56
+ case pattern
57
+ when 'some_base/src1*'
58
+ ['some_base/src1.js', 'some_base/src15.js']
59
+ when 'some_base/src1.js'
60
+ ['some_base/src1.js']
61
+ when 'some_base/src2*'
62
+ ['some_base/src2.js']
63
+ else
64
+ raise "Unexpected pattern received: #{pattern}"
65
+ end
66
+ end
67
+
68
+ expanded_files = Jasmine::PathExpander.expand(
69
+ 'some_base',
70
+ ['src1*', '!src1.js', 'src2*'],
71
+ dir_glob
72
+ )
73
+
74
+ expanded_files.should == [
75
+ File.join('some_base', 'src15.js'),
76
+ File.join('some_base', 'src2.js')
77
+ ]
78
+ end
79
+
80
+ it "passes through files that are not found by the globber and are not negations and not globs" do
81
+ #this is designed to support asset pipeline files that aren't found.
82
+ dir_glob = lambda do |pattern|
83
+ []
84
+ end
85
+
86
+ expanded_files = Jasmine::PathExpander.expand(
87
+ 'some_base',
88
+ ['src1*', '!src1.js', 'src2.js'],
89
+ dir_glob
90
+ )
91
+
92
+ expanded_files.should == [
93
+ File.join('some_base', 'src2.js')
94
+ ]
95
+ end
96
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::PathMapper do
4
+ it "correctly remaps src files" do
5
+ config = double(:config, :src_dir => '/src_dir', :src_path => '/__src__')
6
+ mapper = Jasmine::PathMapper.new(config)
7
+ mapper.map_src_paths(['/src_dir/foo']).should == ['/__src__/foo']
8
+ mapper.map_src_paths(['foo/bar']).should == ['/__src__/foo/bar']
9
+ end
10
+ it "correctly remaps spec files" do
11
+ config = double(:config, :spec_dir => '/spec_dir', :spec_path => '/__spec__')
12
+ mapper = Jasmine::PathMapper.new(config)
13
+ mapper.map_spec_paths(['/spec_dir/foo']).should == ['/__spec__/foo']
14
+ mapper.map_spec_paths(['foo/bar']).should == ['/__spec__/foo/bar']
15
+ end
16
+ it "correctly remaps jasmine files" do
17
+ config = double(:config, :jasmine_dir => '/jasmine_dir', :jasmine_path => '/__jasmine__')
18
+ mapper = Jasmine::PathMapper.new(config)
19
+ mapper.map_jasmine_paths(['/jasmine_dir/foo']).should == ['/__jasmine__/foo']
20
+ mapper.map_jasmine_paths(['foo/bar']).should == ['/__jasmine__/foo/bar']
21
+ end
22
+ it "correctly remaps boot files" do
23
+ config = double(:config, :boot_dir => '/boot_dir', :boot_path => '/__boot__')
24
+ mapper = Jasmine::PathMapper.new(config)
25
+ mapper.map_boot_paths(['/boot_dir/foo']).should == ['/__boot__/foo']
26
+ mapper.map_boot_paths(['foo/bar']).should == ['/__boot__/foo/bar']
27
+ end
28
+ it "handles edge case where dir == path" do
29
+ config = double(:config, :src_dir => '/src_dir', :src_path => '/src_dir')
30
+ mapper = Jasmine::PathMapper.new(config)
31
+ mapper.map_src_paths(['/src_dir/foo']).should == ['/src_dir/foo']
32
+ end
33
+ end
@@ -27,14 +27,14 @@ describe Jasmine::Server do
27
27
  it "should create a Rack::Server with the correct port when passed" do
28
28
  port = 1234
29
29
  Rack::Server.should_receive(:new).with(hash_including(:Port => port)).and_return(double(:server).as_null_object)
30
- Jasmine::Server.new(port).start
30
+ Jasmine::Server.new(port, double(:app)).start
31
31
  end
32
32
 
33
33
  it "should start the server" do
34
34
  server = double(:server)
35
35
  Rack::Server.should_receive(:new) { server.as_null_object }
36
36
  server.should_receive(:start)
37
- Jasmine::Server.new.start
37
+ Jasmine::Server.new('8888', double(:app)).start
38
38
  end
39
39
 
40
40
  it "should set the app as the instance variable on the rack server" do