Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Install examples in a nicer way with the jasmine command
- Don't install them by default with init, now run jasmine examples
- Example files are added to a jasmine_examples folder as the rails
  generator does

[#4781784]
  • Loading branch information
Gregg Van Hove committed Sep 25, 2013
1 parent c83dcd9 commit 4e639f6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
6 changes: 5 additions & 1 deletion generators/jasmine/templates/INSTALL
@@ -1,4 +1,4 @@
Jasmine has been installed with example specs.
Jasmine has been installed.

To run the server:

Expand All @@ -7,3 +7,7 @@ rake jasmine
To run the automated CI task with PhantomJS:

rake jasmine:ci

To install some example javascripts and specs:

jasmine examples
23 changes: 17 additions & 6 deletions lib/jasmine/command_line_tool.rb
Expand Up @@ -44,15 +44,14 @@ def process(argv)
exit 1
end

FileUtils.makedirs('public/javascripts')
FileUtils.makedirs('spec/javascripts')
FileUtils.makedirs('spec/javascripts/support')
FileUtils.makedirs('spec/javascripts/helpers')

copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
unless File.exist?('spec/javascripts/helpers/.gitkeep')
source_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators', 'jasmine', 'install', 'templates', 'spec', 'javascripts', 'helpers', '.gitkeep'))
dest_file = File.expand_path(File.join(Dir.pwd, 'spec', 'javascripts', 'helpers', '.gitkeep'))
FileUtils.copy(source_file, dest_file)
end

copy_unless_exists('spec/javascripts/support/jasmine.yml')
copy_unless_exists('spec/javascripts/support/jasmine_helper.rb')
Expand All @@ -74,11 +73,23 @@ def process(argv)
File.open(template_path('INSTALL'), 'r').each_line do |line|
puts line
end
elsif argv[0] == "examples"
FileUtils.makedirs('public/javascripts/jasmine_examples')
FileUtils.makedirs('spec/javascripts/jasmine_examples')
FileUtils.makedirs('spec/javascripts/helpers/jasmine_examples')

copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/jasmine_examples/Player.js')
copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/jasmine_examples/Song.js')
copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/jasmine_examples/PlayerSpec.js')
copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/jasmine_examples/SpecHelper.js')

puts "Jasmine has installed some examples."
elsif argv[0] == "license"
puts File.new(expand(cwd, "MIT.LICENSE")).read
else
puts "unknown command #{argv}"
puts "Usage: jasmine init"
puts " examples"
puts " license"
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/jasmine_command_line_tool_rakeless_spec.rb
Expand Up @@ -14,7 +14,7 @@
it "should append to an existing Rakefile" do
FileUtils.cp("#{@old_dir}/spec/fixture/Rakefile", @tmp)
output = capture_stdout { Jasmine::CommandLineTool.new.process ["init"] }
output.should =~ /Jasmine has been installed with example specs./
output.should =~ /Jasmine has been installed\./
File.read(File.join(@tmp, 'Rakefile')).should include('jasmine_flunk')
end
end
Expand Down
39 changes: 30 additions & 9 deletions spec/jasmine_command_line_tool_spec.rb
Expand Up @@ -11,12 +11,17 @@
end

describe '.init' do
it 'should create files on init' do
output = capture_stdout { Jasmine::CommandLineTool.new.process ['init'] }
output.should =~ /Jasmine has been installed with example specs./
describe 'without a Gemfile' do
it 'should create files on init' do
output = capture_stdout { Jasmine::CommandLineTool.new.process ['init'] }
output.should =~ /Jasmine has been installed\./

ci_output = `rake --trace jasmine:ci`
ci_output.should =~ (/[1-9][0-9]* specs, 0 failures/)
File.exists?(File.join(@tmp, 'spec/javascripts/helpers/.gitkeep')).should == true
File.exists?(File.join(@tmp, 'spec/javascripts/support/jasmine.yml')).should == true
File.exists?(File.join(@tmp, 'Rakefile')).should == true
ci_output = `rake --trace jasmine:ci`
ci_output.should =~ (/0 specs, 0 failures/)
end
end

describe 'with a Gemfile containing Rails' do
Expand All @@ -43,9 +48,10 @@
Jasmine::CommandLineTool.new.process ['init', '--force']
}.not_to raise_error
}
output.should =~ /Jasmine has been installed with example specs./
output.should =~ /Jasmine has been installed\./

Dir.entries(@tmp).sort.should == [".", "..", "Gemfile", "Rakefile", "public", "spec"]
File.exists?(File.join(@tmp, 'spec/javascripts/helpers/.gitkeep')).should == true
File.exists?(File.join(@tmp, 'spec/javascripts/support/jasmine.yml')).should == true
end
end

Expand All @@ -62,13 +68,28 @@
Jasmine::CommandLineTool.new.process ['init']
}.not_to raise_error
}
output.should =~ /Jasmine has been installed with example specs./
output.should =~ /Jasmine has been installed\./

Dir.entries(@tmp).sort.should == [".", "..", "Gemfile", "Rakefile", "public", "spec"]
File.exists?(File.join(@tmp, 'spec/javascripts/helpers/.gitkeep')).should == true
File.exists?(File.join(@tmp, 'spec/javascripts/support/jasmine.yml')).should == true
end
end
end

describe '.examples' do
it 'should install the examples' do
output = capture_stdout { Jasmine::CommandLineTool.new.process ['examples'] }
output.should =~ /Jasmine has installed some examples\./
File.exists?(File.join(@tmp, 'public/javascripts/jasmine_examples/Player.js')).should == true
File.exists?(File.join(@tmp, 'public/javascripts/jasmine_examples/Song.js')).should == true
File.exists?(File.join(@tmp, 'spec/javascripts/jasmine_examples/PlayerSpec.js')).should == true
File.exists?(File.join(@tmp, 'spec/javascripts/helpers/jasmine_examples/SpecHelper.js')).should == true

capture_stdout { Jasmine::CommandLineTool.new.process ['init'] }
ci_output = `rake --trace jasmine:ci`
ci_output.should =~ (/[1-9]\d* specs, 0 failures/)
end
end

it 'should include license info' do
output = capture_stdout { Jasmine::CommandLineTool.new.process ['license'] }
Expand Down
10 changes: 6 additions & 4 deletions spec/jasmine_pojs_spec.rb
Expand Up @@ -17,18 +17,19 @@
context "when the Jasmine generators are available" do
before :each do
`jasmine init`
`jasmine examples`
end

it "should find the Jasmine configuration files" do
File.exists?("spec/javascripts/support/jasmine.yml").should == true
end

it "should find the Jasmine example files" do
File.exists?("public/javascripts/Player.js").should == true
File.exists?("public/javascripts/Song.js").should == true
File.exists?("public/javascripts/jasmine_examples/Player.js").should == true
File.exists?("public/javascripts/jasmine_examples/Song.js").should == true

File.exists?("spec/javascripts/PlayerSpec.js").should == true
File.exists?("spec/javascripts/helpers/SpecHelper.js").should == true
File.exists?("spec/javascripts/jasmine_examples/PlayerSpec.js").should == true
File.exists?("spec/javascripts/helpers/jasmine_examples/SpecHelper.js").should == true

File.exists?("spec/javascripts/support/jasmine.yml").should == true
end
Expand All @@ -41,6 +42,7 @@

it "should successfully run rake jasmine:ci" do
output = `rake jasmine:ci`
output.should =~ (/[1-9]\d* specs, 0 failures/)
end

end
Expand Down

0 comments on commit 4e639f6

Please sign in to comment.