2011-04-15 18:55:37 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
describe 'backbone-generator' do
|
|
|
|
def clean!
|
|
|
|
FileUtils.rm_rf 'public'
|
|
|
|
FileUtils.rm_rf 'spec/javascripts'
|
|
|
|
FileUtils.rm_rf 'app'
|
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
def run(*opts)
|
|
|
|
system %{bin/backbone-generator #{opts.join(' ')}}
|
|
|
|
end
|
|
|
|
|
2011-04-15 18:55:37 +00:00
|
|
|
before { clean! }
|
|
|
|
after { clean! }
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'coffeescript' do
|
2011-05-09 02:44:21 +00:00
|
|
|
def should_generate_model
|
|
|
|
File.file?(model = 'app/coffeescripts/models/section/model.coffee').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/models/section/model_spec.coffee').should be_true
|
|
|
|
|
|
|
|
File.read(model).should match(/SectionModel/)
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_generate_view
|
|
|
|
File.file?(view = 'app/coffeescripts/views/section/model_view.coffee').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/model_view_spec.coffee').should be_true
|
|
|
|
File.file?(template = 'app/views/section/models/view.jst').should be_true
|
|
|
|
|
|
|
|
File.read(view).should match(/SectionModel/)
|
|
|
|
File.read(view).should match(%r{template: JST\['section/models/view'\]})
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_generate_collection
|
|
|
|
File.file?(collection = 'app/coffeescripts/collections/section/models.coffee').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/collections/section/models_spec.coffee').should be_true
|
|
|
|
|
|
|
|
File.read(collection).should match(/SectionModels/)
|
|
|
|
File.read(collection).should_not match(/SectionModelss/)
|
|
|
|
File.read(collection).should match(%r{section/model})
|
|
|
|
File.read(spec).should match(/SectionModels/)
|
|
|
|
File.read(spec).should_not match(/SectionModelss/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_generate_collection_view
|
|
|
|
File.file?(view = 'app/coffeescripts/views/section/models_view.coffee').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/models_view_spec.coffee').should be_true
|
|
|
|
File.file?(template = 'app/views/section/models/list.jst').should be_true
|
|
|
|
|
|
|
|
File.read(view).should match(/SectionModelsView/)
|
|
|
|
File.read(view).should_not match(/SectionModelssView/)
|
|
|
|
File.read(view).should match(/SectionModelView/)
|
|
|
|
File.read(view).should match(%r{template: JST\['section/models/list'\]})
|
|
|
|
File.read(spec).should match(/SectionModelsView/)
|
|
|
|
File.read(spec).should_not match(/SectionModelssView/)
|
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'model' do
|
2011-05-09 02:44:21 +00:00
|
|
|
it "should generate the model files" do
|
|
|
|
run "model", "Section::Model", '--coffee'
|
|
|
|
|
|
|
|
should_generate_model
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'view' do
|
|
|
|
it "should generate the model files" do
|
|
|
|
run "view", "Section::Model", '--coffee'
|
|
|
|
|
|
|
|
should_generate_view
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'collection view' do
|
|
|
|
it "should generate the collection view files" do
|
|
|
|
run "collection-view", "Section::Model", '--coffee'
|
|
|
|
|
|
|
|
should_generate_collection_view
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'collection' do
|
|
|
|
it "should generate the collection files" do
|
|
|
|
run "collection", "Section::Model", '--coffee'
|
|
|
|
|
|
|
|
should_generate_collection
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'scaffold' do
|
|
|
|
it "should generate everything!" do
|
|
|
|
run "scaffold", "Section::Model", '--coffee'
|
|
|
|
|
|
|
|
should_generate_model
|
|
|
|
should_generate_view
|
|
|
|
should_generate_collection
|
|
|
|
should_generate_collection_view
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'spec helper' do
|
|
|
|
it "should generate a spec helper" do
|
|
|
|
run "spec-helper", '--coffee'
|
|
|
|
|
|
|
|
File.file?(collection = 'spec/javascripts/helpers/backbone_spec_helper.coffee').should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'app helper' do
|
|
|
|
it "should generate an app helper" do
|
|
|
|
run "app-helper", '--coffee'
|
|
|
|
|
|
|
|
File.file?(collection = 'app/coffeescripts/applications/backbone_helper.coffee').should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'application scaffold' do
|
|
|
|
it "should generate an application scaffold" do
|
|
|
|
run "app-scaffold", '--coffee'
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-09 02:44:21 +00:00
|
|
|
File.file?(app = 'app/coffeescripts/application/app_view.coffee').should be_true
|
|
|
|
File.file?(app_view = 'app/views/application/app_view.jst').should be_true
|
|
|
|
File.file?(controller = 'app/coffeescripts/application/controller.coffee').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/application/app_view_spec.coffee').should be_true
|
|
|
|
end
|
2011-05-07 16:50:06 +00:00
|
|
|
end
|
2011-04-16 00:43:48 +00:00
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'javascript' do
|
|
|
|
def should_generate_model
|
|
|
|
File.file?(model = 'public/javascripts/models/section/model.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/models/section/model_spec.js').should be_true
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.read(model).should match(/SectionModel/)
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
def should_generate_view
|
|
|
|
File.file?(view = 'public/javascripts/views/section/model_view.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/model_view_spec.js').should be_true
|
|
|
|
File.file?(template = 'app/views/section/models/view.jst').should be_true
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.read(view).should match(/SectionModel/)
|
|
|
|
File.read(view).should match(/return this/)
|
|
|
|
File.read(view).should match(%r{template: JST\['section/models/view'\]})
|
|
|
|
File.read(spec).should match(/SectionModel/)
|
|
|
|
end
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
def should_generate_collection
|
|
|
|
File.file?(collection = 'public/javascripts/collections/section/models.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/collections/section/models_spec.js').should be_true
|
2011-04-16 00:43:48 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.read(collection).should match(/SectionModels/)
|
|
|
|
File.read(collection).should_not match(/SectionModelss/)
|
|
|
|
File.read(collection).should match(%r{section/model})
|
|
|
|
File.read(spec).should match(/SectionModels/)
|
|
|
|
File.read(spec).should_not match(/SectionModelss/)
|
|
|
|
end
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
def should_generate_collection_view
|
|
|
|
File.file?(view = 'public/javascripts/views/section/models_view.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/views/section/models_view_spec.js').should be_true
|
|
|
|
File.file?(template = 'app/views/section/models/list.jst').should be_true
|
|
|
|
|
|
|
|
File.read(view).should match(/SectionModelsView/)
|
|
|
|
File.read(view).should_not match(/SectionModelssView/)
|
|
|
|
File.read(view).should match(/SectionModelView/)
|
|
|
|
File.read(view).should match(/return this/)
|
|
|
|
File.read(view).should match(%r{template: JST\['section/models/list'\]})
|
|
|
|
File.read(spec).should match(/SectionModelsView/)
|
|
|
|
File.read(spec).should_not match(/SectionModelssView/)
|
2011-04-15 18:55:37 +00:00
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'model' do
|
|
|
|
it "should generate the model files" do
|
|
|
|
run "model", "Section::Model"
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_model
|
|
|
|
end
|
2011-04-15 19:32:04 +00:00
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'view' do
|
|
|
|
it "should generate the view files" do
|
|
|
|
run "view", "Section::Model"
|
2011-04-15 19:32:04 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_view
|
2011-04-18 15:36:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'collection view' do
|
|
|
|
context 'without trailing s' do
|
|
|
|
it "should generate the collection view files" do
|
|
|
|
run "collection-view", "Section::Model"
|
2011-04-18 15:36:46 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_collection_view
|
|
|
|
end
|
2011-04-18 15:36:46 +00:00
|
|
|
end
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
context 'with trailing s' do
|
|
|
|
it "should generate the collection view files" do
|
|
|
|
run "collection-view", "Section::Models"
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_collection_view
|
|
|
|
end
|
2011-04-18 15:36:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'collection' do
|
|
|
|
context 'without trailing s' do
|
|
|
|
it "should generate the collection files" do
|
|
|
|
run "collection", "Section::Model"
|
2011-04-18 15:36:46 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_collection
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with trailing s' do
|
|
|
|
it "should generate the collection files" do
|
|
|
|
run "collection", "Section::Models"
|
|
|
|
|
|
|
|
should_generate_collection
|
|
|
|
end
|
2011-04-18 15:36:46 +00:00
|
|
|
end
|
2011-04-16 00:43:48 +00:00
|
|
|
end
|
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'scaffold' do
|
|
|
|
it "should generate everything!" do
|
|
|
|
run "scaffold", "Section::Model"
|
2011-04-15 18:55:37 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
should_generate_model
|
|
|
|
should_generate_view
|
|
|
|
should_generate_collection
|
|
|
|
should_generate_collection_view
|
|
|
|
end
|
2011-04-15 18:55:37 +00:00
|
|
|
end
|
2011-04-18 13:32:43 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'spec helper' do
|
|
|
|
it "should generate a spec helper" do
|
|
|
|
run "spec-helper"
|
2011-04-18 13:32:43 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.file?(collection = 'spec/javascripts/helpers/backbone_spec_helper.js').should be_true
|
|
|
|
end
|
2011-04-18 13:32:43 +00:00
|
|
|
end
|
2011-04-23 15:13:54 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'app helper' do
|
|
|
|
it "should generate an app helper" do
|
|
|
|
run "app-helper"
|
2011-04-23 15:13:54 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.file?(collection = 'public/javascripts/applications/backbone_helper.js').should be_true
|
|
|
|
end
|
2011-04-23 15:13:54 +00:00
|
|
|
end
|
2011-04-23 23:00:22 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
describe 'application scaffold' do
|
|
|
|
it "should generate an application scaffold" do
|
|
|
|
run "app-scaffold"
|
2011-04-23 23:00:22 +00:00
|
|
|
|
2011-05-07 16:50:06 +00:00
|
|
|
File.file?(app = 'public/javascripts/application/app_view.js').should be_true
|
|
|
|
File.file?(app_view = 'app/views/application/app_view.jst').should be_true
|
|
|
|
File.file?(controller = 'public/javascripts/application/controller.js').should be_true
|
|
|
|
File.file?(spec = 'spec/javascripts/application/app_view_spec.js').should be_true
|
|
|
|
end
|
2011-04-23 23:00:22 +00:00
|
|
|
end
|
|
|
|
end
|
2011-04-15 18:55:37 +00:00
|
|
|
end
|