jasmine 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,8 +20,8 @@ end
20
20
 
21
21
  def copy_unless_exists(relative_path, dest_path = nil)
22
22
  unless File.exist?(dest_path(relative_path))
23
- File.copy(template_path(relative_path), dest_path(dest_path || relative_path))
24
- end
23
+ File.copy(template_path(relative_path), dest_path(dest_path || relative_path))
24
+ end
25
25
  end
26
26
 
27
27
  if ARGV[0] == 'init'
@@ -37,16 +37,19 @@ if ARGV[0] == 'init'
37
37
  rails_tasks_dir = dest_path('lib/tasks')
38
38
  if File.exist?(rails_tasks_dir)
39
39
  copy_unless_exists('lib/tasks/jasmine.rake')
40
- copy_unless_exists('spec/javascripts/support/sources-rails.yaml', 'spec/javascripts/support/sources.yaml')
40
+ copy_unless_exists('spec/javascripts/support/jasmine-rails.yaml', 'spec/javascripts/support/jasmine.yaml')
41
41
  else
42
- copy_unless_exists('spec/javascripts/support/sources.yaml')
42
+ copy_unless_exists('spec/javascripts/support/jasmine.yaml')
43
+ write_mode = 'w'
43
44
  if File.exist?(dest_path('Rakefile'))
44
45
  load dest_path('Rakefile')
46
+ write_mode = 'a'
47
+ end
48
+ unless Rake::Task.task_defined?('jasmine')
49
+ File.open(dest_path('Rakefile'), write_mode) do |f|
50
+ f.write(File.read(template_path('lib/tasks/jasmine.rake')))
51
+ end
45
52
  end
46
- write_mode = Rake::Task.task_defined?('jasmine') ? 'a' : 'w'
47
- File.open(dest_path('Rakefile'), write_mode) do |f|
48
- f.write(File.read(template_path('lib/tasks/jasmine.rake')))
49
- end
50
53
  end
51
54
  File.open(template_path('INSTALL'), 'r').each_line do |line|
52
55
  puts line
@@ -9,7 +9,7 @@ class JasmineGenerator < Rails::Generator::Base
9
9
  m.directory "spec/javascripts/support"
10
10
  m.file "spec/javascripts/support/jasmine_config.rb", "spec/javascripts/support/jasmine_config.rb"
11
11
  m.file "spec/javascripts/support/jasmine_spec.rb", "spec/javascripts/support/jasmine_spec.rb"
12
- m.file "spec/javascripts/support/sources-rails.yaml", "spec/javascripts/support/sources.yaml"
12
+ m.file "spec/javascripts/support/jasmine-rails.yaml", "spec/javascripts/support/jasmine.yaml"
13
13
 
14
14
  m.directory "lib/tasks"
15
15
  m.file "lib/tasks/jasmine.rake", "lib/tasks/jasmine.rake"
@@ -1,8 +1,10 @@
1
- sources:
1
+ src_files:
2
2
  - javascripts/prototype.js
3
3
  - javascripts/effects.js
4
4
  - javascripts/controls.js
5
5
  - javascripts/dragdrop.js
6
6
  - javascripts/application.js
7
+ spec_files:
8
+ - **/*.js
7
9
  src_dir: public
8
- spec_dir: spec/javascripts
10
+ spec_dir: spec/javascripts
@@ -0,0 +1,10 @@
1
+ #src_files:
2
+ # - lib/source1.js
3
+ # - lib/source2.js
4
+ # - dist/**/*.js
5
+ #stylesheets:
6
+ # - css/style.css
7
+ #spec_files:
8
+ # -
9
+ #src_dir:
10
+ #spec_dir: spec/javascripts
@@ -2,22 +2,58 @@ require 'jasmine'
2
2
 
3
3
  class Jasmine::Config
4
4
 
5
- def project_root
6
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."))
7
- end
5
+ # def project_root
6
+ # Dir.pwd
7
+ # end
8
8
 
9
- # Return an array of files to include before jasmine specs. Override if needed.
10
- # def src_files
11
- # match_files(src_dir, "**/*.js")
9
+ # Path to your jasmine.yaml
10
+ # def simple_config_file
11
+ # File.join(project_root, 'spec/javascripts/support/jasmine.yaml')
12
12
  # end
13
13
 
14
- # Path to your JavaScript source files
14
+ # Source directory path. Your src_files must be returned relative to this path.
15
15
  # def src_dir
16
- # File.join(project_root, "public")
16
+ # if simple_config['src_dir']
17
+ # File.join(project_root, simple_config['src_dir'])
18
+ # else
19
+ # project_root
20
+ # end
17
21
  # end
18
22
 
19
- # Path to your JavaScript specs
23
+ # Spec directory path. Your spec_files must be returned relative to this path.
20
24
  # def spec_dir
21
- # File.join(project_root, 'spec/javascripts')
25
+ # if simple_config['spec_dir']
26
+ # File.join(project_root, simple_config['spec_dir'])
27
+ # else
28
+ # File.join(project_root, 'spec/javascripts')
29
+ # end
30
+ # end
31
+
32
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
33
+ # def src_files
34
+ # files = []
35
+ # if simple_config['src_files']
36
+ # files = simple_config['src_files'].collect {|filepath| Dir.glob(filepath)}
37
+ # end
38
+ # files
22
39
  # end
40
+
41
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
42
+ # def spec_files
43
+ # files = match_files(spec_dir, "**/*.js")
44
+ # if simple_config['spec_files']
45
+ # files = simple_config['spec_files'].collect {|filepath| Dir.glob(filepath)}
46
+ # end
47
+ # files
48
+ # end
49
+
50
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
51
+ # def stylesheets
52
+ # files = []
53
+ # if simple_config['stylesheets']
54
+ # files = simple_config['stylesheets'].collect {|filepath| Dir.glob(filepath)}
55
+ # end
56
+ # files
57
+ # end
58
+
23
59
  end
@@ -71,27 +71,54 @@ module Jasmine
71
71
  @client.eval_js(script)
72
72
  end
73
73
 
74
- def stylesheets
75
- []
74
+ def match_files(dir, patterns)
75
+ dir = File.expand_path(dir)
76
+ patterns.collect do |pattern|
77
+ Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
78
+ end.flatten
76
79
  end
77
80
 
78
- def src_files
79
- []
81
+ def simple_config
82
+ config = File.exist?(simple_config_file) ? File.open(simple_config_file) { |yf| YAML::load( yf ) } : false
83
+ config || {}
80
84
  end
81
85
 
82
- def spec_files
83
- raise "You need to declare a spec_files method in #{self.class}!"
86
+
87
+ def spec_path
88
+ "/__spec__"
84
89
  end
85
90
 
86
- def match_files(dir, pattern)
87
- dir = File.expand_path(dir)
88
- Dir.glob(File.join(dir, pattern)).collect {|f| f.sub("#{dir}/", "")}.sort
91
+ def root_path
92
+ "/__root__"
93
+ end
94
+
95
+ def mappings
96
+ {
97
+ spec_path => spec_dir,
98
+ root_path => project_root
99
+ }
100
+ end
101
+
102
+ def js_files
103
+ src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) }
104
+ end
105
+
106
+ def css_files
107
+ stylesheets.collect {|f| "/" + f }
108
+ end
109
+
110
+ def spec_files_full_paths
111
+ spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
89
112
  end
90
113
 
91
114
  def project_root
92
115
  Dir.pwd
93
116
  end
94
117
 
118
+ def simple_config_file
119
+ File.join(project_root, 'spec/javascripts/support/jasmine.yaml')
120
+ end
121
+
95
122
  def src_dir
96
123
  if simple_config['src_dir']
97
124
  File.join(project_root, simple_config['src_dir'])
@@ -100,19 +127,6 @@ module Jasmine
100
127
  end
101
128
  end
102
129
 
103
- def simple_config_file
104
- File.join(project_root, 'spec/javascripts/support/sources.yaml')
105
- end
106
-
107
- def simple_config
108
- config = File.exist?(simple_config_file) ? File.open(simple_config_file) { |yf| YAML::load( yf ) } : false
109
- config || {}
110
- end
111
-
112
- def src_files
113
- simple_config['sources'] || []
114
- end
115
-
116
130
  def spec_dir
117
131
  if simple_config['spec_dir']
118
132
  File.join(project_root, simple_config['spec_dir'])
@@ -121,31 +135,29 @@ module Jasmine
121
135
  end
122
136
  end
123
137
 
124
- def spec_files
125
- match_files(spec_dir, "**/*.js")
126
- end
127
-
128
- def spec_path
129
- "/__spec__"
130
- end
131
-
132
- def root_path
133
- "/__root__"
138
+ def src_files
139
+ files = []
140
+ if simple_config['src_files']
141
+ files = match_files(src_dir, simple_config['src_files'])
142
+ end
143
+ files
134
144
  end
135
145
 
136
- def mappings
137
- {
138
- spec_path => spec_dir,
139
- root_path => project_root
140
- }
146
+ def spec_files
147
+ files = match_files(spec_dir, "**/*.js")
148
+ if simple_config['spec_files']
149
+ files = match_files(spec_dir, simple_config['spec_files'])
150
+ end
151
+ files
141
152
  end
142
153
 
143
- def js_files
144
- src_files.collect {|f| "/" + f } + spec_files.collect {|f| File.join(spec_path, f) }
154
+ def stylesheets
155
+ files = []
156
+ if simple_config['stylesheets']
157
+ files = match_files(src_dir, simple_config['stylesheets'])
158
+ end
159
+ files
145
160
  end
146
161
 
147
- def spec_files_full_paths
148
- spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
149
- end
150
162
  end
151
163
  end
@@ -18,7 +18,7 @@ module Jasmine
18
18
  #noinspection RubyUnusedLocalVariable
19
19
  def run
20
20
  jasmine_files = @jasmine_files
21
- css_files = @jasmine_stylesheets + (@config.stylesheets || [])
21
+ css_files = @jasmine_stylesheets + (@config.css_files || [])
22
22
  js_files = @config.js_files
23
23
 
24
24
  body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html.erb"))).result(binding)
@@ -12,6 +12,7 @@ describe Jasmine::Config do
12
12
  it "if sources.yaml not found" do
13
13
  File.stub!(:exist?).and_return(false)
14
14
  @config.src_files.should == []
15
+ @config.stylesheets.should == []
15
16
  @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
16
17
  @config.mappings.should == {
17
18
  '/__root__' => @config.project_root,
@@ -20,8 +21,10 @@ describe Jasmine::Config do
20
21
  end
21
22
 
22
23
  it "if sources.yaml is empty" do
24
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
23
25
  YAML.stub!(:load).and_return(false)
24
26
  @config.src_files.should == []
27
+ @config.stylesheets.should == []
25
28
  @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
26
29
  @config.mappings.should == {
27
30
  '/__root__' => @config.project_root,
@@ -29,8 +32,8 @@ describe Jasmine::Config do
29
32
  }
30
33
  end
31
34
 
32
- it "using default sources.yaml" do
33
- @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources.yaml'))
35
+ it "using default jasmine.yaml" do
36
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
34
37
  @config.src_files.should == []
35
38
  @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
36
39
  @config.mappings.should == {
@@ -39,14 +42,31 @@ describe Jasmine::Config do
39
42
  }
40
43
  end
41
44
 
42
- it "using rails sources.yaml" do
43
- @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/sources-rails.yaml'))
45
+ it "simple_config stylesheets" do
46
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine.yaml'))
47
+ YAML.stub!(:load).and_return({'stylesheets' => ['foo.css', 'bar.css']})
48
+ Dir.stub!(:glob).and_return do |glob_string|
49
+ glob_string
50
+ end
51
+ @config.stylesheets.should == ['foo.css', 'bar.css']
52
+ end
53
+
54
+ it "using rails jasmine.yaml" do
55
+ original_glob = Dir.method(:glob)
56
+ Dir.stub!(:glob).and_return do |glob_string|
57
+ if glob_string =~ /public/
58
+ glob_string
59
+ else
60
+ original_glob.call(glob_string)
61
+ end
62
+ end
63
+ @config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yaml'))
64
+ @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
44
65
  @config.src_files.should == ['javascripts/prototype.js',
45
66
  'javascripts/effects.js',
46
67
  'javascripts/controls.js',
47
68
  'javascripts/dragdrop.js',
48
69
  'javascripts/application.js']
49
- @config.spec_files.should == ['javascripts/ExampleSpec.js', 'javascripts/SpecHelper.js']
50
70
  @config.js_files.should == [
51
71
  '/javascripts/prototype.js',
52
72
  '/javascripts/effects.js',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Agaskar
@@ -87,10 +87,10 @@ files:
87
87
  - generators/jasmine/templates/lib/tasks/jasmine.rake
88
88
  - generators/jasmine/templates/spec/javascripts/ExampleSpec.js
89
89
  - generators/jasmine/templates/spec/javascripts/SpecHelper.js
90
+ - generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yaml
91
+ - generators/jasmine/templates/spec/javascripts/support/jasmine.yaml
90
92
  - generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb
91
93
  - generators/jasmine/templates/spec/javascripts/support/jasmine_spec.rb
92
- - generators/jasmine/templates/spec/javascripts/support/sources-rails.yaml
93
- - generators/jasmine/templates/spec/javascripts/support/sources.yaml
94
94
  - jasmine/contrib/ruby/jasmine_runner.rb
95
95
  - jasmine/contrib/ruby/jasmine_spec_builder.rb
96
96
  - jasmine/contrib/ruby/run.html
@@ -1,5 +0,0 @@
1
- #sources:
2
- # - lib/source1.js
3
- # - lib/source2.js
4
- #src_dir:
5
- #spec_dir: spec/javascripts