Class: JasmineDev

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/jasmine/tasks/jasmine_dev/base.rb,
lib/jasmine/tasks/jasmine_dev/js_hint.rb,
lib/jasmine/tasks/jasmine_dev/release.rb,
lib/jasmine/tasks/jasmine_dev/sources.rb,
lib/jasmine/tasks/jasmine_dev/version.rb,
lib/jasmine/tasks/jasmine_dev/count_specs.rb,
lib/jasmine/tasks/jasmine_dev/execute_specs.rb,
lib/jasmine/tasks/jasmine_dev/build_distribution.rb,
lib/jasmine/tasks/jasmine_dev/build_github_pages.rb,
lib/jasmine/tasks/jasmine_dev/build_standalone_runner.rb,
lib/jasmine/tasks/jasmine_dev/build_standalone_distribution.rb

Constant Summary collapse

JASMINE_SOURCES =
{
  :core => [
    "base.js",
    "util.js",
    "Env.js",
    "Reporter.js",
    "Block.js",
    "JsApiReporter.js",
    "Matchers.js",
    "mock-timeout.js",
    "MultiReporter.js",
    "NestedResults.js",
    "PrettyPrinter.js",
    "Queue.js",
    "Runner.js",
    "Spec.js",
    "Suite.js",
    "WaitsBlock.js",
    "WaitsForBlock.js"
  ],

  :html => [
    "HtmlReporterHelpers.js",
    "HtmlReporter.js",
    "ReporterView.js",
    "SpecView.js",
    "SuiteView.js",
    "TrivialReporter.js"
  ]
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.project_rootObject


15
16
17
# File 'lib/jasmine/tasks/jasmine_dev/base.rb', line 15

def self.project_root
  File.join(JasmineDev.source_root, '..', '..')
end

.source_pathsObject


8
9
10
11
12
13
# File 'lib/jasmine/tasks/jasmine_dev/base.rb', line 8

def self.source_paths
  [
    File.join(JasmineDev.project_root, 'lib', 'jasmine-core'),
    JasmineDev.project_root
  ]
end

.source_rootObject


4
5
6
# File 'lib/jasmine/tasks/jasmine_dev/base.rb', line 4

def self.source_root
  File.dirname(__FILE__)
end

.spacerObject


19
20
21
# File 'lib/jasmine/tasks/jasmine_dev/base.rb', line 19

def self.spacer
  "\n--------------------"
end

Instance Method Details

#build_distribution(directory = "./lib/jasmine-core") ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jasmine/tasks/jasmine_dev/build_distribution.rb', line 4

def build_distribution(directory = "./lib/jasmine-core")
  invoke :js_hint

  say JasmineDev.spacer

  say "Building Jasmine distribution from source into #{directory}", :cyan

  say 'Building JavaScript...', :yellow

  inside directory do
    create_file "jasmine.js",
                concat_contents_of(jasmine_js_paths),
                :force => true
    create_file "jasmine-html.js",
                concat_contents_of(jasmine_html_js_paths),
                :force => true
  end

  say 'Building CSS...', :yellow

  run "compass compile", :capture => true

  copy_file File.join("#{JasmineDev.project_root}", 'src', 'html', 'jasmine.css'),
            File.join(directory, 'jasmine.css')
end

#build_github_pages(pages_dir = File.expand_path(File.join('.', 'pages'))) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jasmine/tasks/jasmine_dev/build_github_pages.rb', line 4

def build_github_pages(pages_dir = File.expand_path(File.join('.', 'pages')))
  say JasmineDev.spacer

  say "Building Github Pages...", :cyan

  return unless pages_submodule_installed?

  project_lib_dir = File.join(JasmineDev.project_root, 'lib', 'jasmine-core')

  pages_lib_dir = File.join(pages_dir, 'lib')
  FileUtils.rm_r(pages_lib_dir) if File.exist?(pages_lib_dir)

  ['jasmine.js', 'jasmine-html.js', 'jasmine.css'].each do |file|
    copy_file File.join(project_lib_dir, file), File.join(pages_lib_dir, file)
  end

  inside File.join(JasmineDev.project_root, 'pages', 'src') do
    run_with_output "bundle exec rocco -l js introduction.js -t layout.mustache -o #{pages_dir}"
  end

  inside pages_dir do
    copy_file File.join(pages_dir,'introduction.html'), File.join(pages_dir,'index.html')
  end
end

#build_standalone_distribution(download_dir = File.expand_path(File.join('.', 'pages', 'downloads'))) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jasmine/tasks/jasmine_dev/build_standalone_distribution.rb', line 5

def build_standalone_distribution(download_dir = File.expand_path(File.join('.', 'pages', 'downloads')))
  invoke :build_distribution

  say JasmineDev.spacer

  say "Building standalone distribution...", :cyan

  say "Staging files...", :yellow

  lib_files.each do |f|
    copy_file f, File.join(standalone_temp_dir, 'lib', "jasmine-#{version_string}", f)
  end

  ['src', 'spec'].each do |dir|
    directory File.join('lib', 'jasmine-core', 'example', dir),
              File.join(standalone_temp_dir, dir)
  end

  invoke :build_standalone_runner

  say "Zipping distribution...", :yellow

  inside standalone_temp_dir do
    run_with_output "zip -rq ../jasmine-standalone-#{version_string}.zip ."

    say "Copying Zip file to downloads directory", :yellow
    run "mkdir -p #{download_dir}"
    run "cp ../jasmine-standalone-#{version_string}.zip #{download_dir}/"
  end

end

#build_standalone_runnerObject


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jasmine/tasks/jasmine_dev/build_standalone_runner.rb', line 6

def build_standalone_runner
  say JasmineDev.spacer

  say "Building standalone runner HTML...", :cyan

  create_file File.join(standalone_temp_dir, 'SpecRunner.html') do
    template = Tilt.new(File.join('spec', 'templates','runner.html.erb'))

    scope = OpenStruct.new(:title => "Jasmine Spec Runner",
                           :favicon => example_favicon,
                           :jasmine_tags => example_jasmine_tags,
                           :source_tags => example_source_tags,
                           :spec_file_tags => example_spec_tags)
    template.render(scope)
  end
end

#count_specsObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jasmine/tasks/jasmine_dev/count_specs.rb', line 4

def count_specs
  say JasmineDev.spacer
  say "Counting specs...", :cyan

  core_spec_count = count_specs_in(File.join('spec', 'core'))
  console_spec_count = count_specs_in(File.join('spec', 'console'))
  html_spec_count = count_specs_in(File.join('spec', 'html'))

  say "#{(core_spec_count + console_spec_count).to_s} ", :yellow
  say "specs for Node.js runner (exclude DOM-related specs)"
  say "#{(core_spec_count + console_spec_count + html_spec_count).to_s} ", :yellow
  say "specs for Browser runner (all specs)"
  say "\n"
  say "Please verify that these numbers match the runner output."
end

#display_versionObject


30
31
32
33
34
35
36
37
38
39
# File 'lib/jasmine/tasks/jasmine_dev/version.rb', line 30

def display_version

  say "Current version information from src/version.json", :cyan

  say "Display version: "
  say "#{version_string}", :yellow

  say "Version object: "
  say "#{version_object_old}", :yellow
end

#execute_specsObject


35
36
37
38
# File 'lib/jasmine/tasks/jasmine_dev/execute_specs.rb', line 35

def execute_specs
  invoke :execute_specs_in_node
  invoke :execute_specs_in_browser
end

#execute_specs_in_browserObject


22
23
24
25
26
27
28
29
30
31
# File 'lib/jasmine/tasks/jasmine_dev/execute_specs.rb', line 22

def execute_specs_in_browser
  invoke :build_distribution
  invoke :count_specs

  say JasmineDev.spacer

  say "Running all appropriate specs via the default web browser...", :cyan

  open_specs_in_browser
end

#execute_specs_in_nodeObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jasmine/tasks/jasmine_dev/execute_specs.rb', line 5

def execute_specs_in_node
  return unless node_installed?

  invoke :build_distribution
  invoke :count_specs

  say JasmineDev.spacer

  say "Running all appropriate specs via Node.js...", :cyan

  with_color_option = STDOUT.isatty ? "--color" : "--noColor"

  run_with_output "node spec/node_suite.js #{with_color_option}", :capture => true
end

#js_hintObject


4
5
6
7
8
9
10
11
12
# File 'lib/jasmine/tasks/jasmine_dev/js_hint.rb', line 4

def js_hint
  say JasmineDev.spacer

  return unless node_installed?

  say "Running JSHint on Jasmine source and specs...", :cyan

  run_with_output "node jshint/run.js", :capture => true
end

#release_prepObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/jasmine/tasks/jasmine_dev/release.rb', line 4

def release_prep
  say JasmineDev.spacer

  say "Building Release...", :cyan

  return unless pages_submodule_installed?

  invoke :write_version_files
  invoke :build_distribution
  invoke :build_standalone_distribution
  invoke :build_github_pages
end

#write_version_filesObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jasmine/tasks/jasmine_dev/version.rb', line 5

def write_version_files
  say JasmineDev.spacer

  say "Building version files", :cyan

  scope = OpenStruct.new(:major => version_object["major"],
                         :minor => version_object["minor"],
                         :build => version_object["build"],
                         :release_candidate => version_object["release_candidate"],
                         :revision => Time.now.to_i)

  js_template = Tilt.new(File.join(JasmineDev.project_root, 'src', 'templates', 'version.js.erb'))
  create_file File.join(JasmineDev.project_root, 'src', 'version.js'), :force => true do
    js_template.render(scope)
  end

  rb_template = Tilt.new(File.join(JasmineDev.project_root, 'src', 'templates', 'version.rb.erb'))

  create_file File.join(JasmineDev.project_root, 'lib', 'jasmine-core', 'version.rb'), :force => true do
    rb_template.render(scope)
  end
end