some generators specs, add focused option to spec_helper

arnaud sellenet committed Apr 07, 2014
commit 2926c50f2bdcd697b295cff6afb8233f06124642
Showing 4 changed files with 114 additions and 6 deletions
spec/generators/content_type_spec.rb +59 -0
@@ @@ -0,0 +1,59 @@
+ require_relative 'generators_helper'
+ require 'locomotive/wagon/generators/content_type'
+
+ describe Locomotive::Wagon::Generators::ContentType do
+
+ subject { Locomotive::Wagon::Generators::ContentType.new(args, {}, {}) }
+ let(:target_path) { Dir.mktmpdir }
+ after { FileUtils.remove_entry_secure target_path }
+
+ context 'regular arguments' do
+ let(:args) { [ 'posts', target_path, [ 'title', 'body:text', 'published_at:date:true' ] ] }
+ let(:content_type_file) { File.join target_path, 'app','content_types','posts.yml' }
+ let(:expected_data) do
+ {
+ 'name'=>'Posts', 'slug'=>'posts',
+ 'description'=>'A description of the content type for the editors',
+ 'label_field_name'=>'title', 'order_by'=>'manually',
+ 'fields'=>
+ [
+ {
+ 'title'=>
+ {
+ 'label'=>'Title', 'type'=>'string',
+ 'required'=>true, 'hint'=>'Explanatory text displayed in the back office', 'localized'=>false
+ }
+ },
+ {
+ 'body'=>
+ {
+ 'label'=>'Body', 'type'=>'text',
+ 'required'=>false, 'hint'=>'Explanatory text displayed in the back office', 'localized'=>false
+ }
+ },
+ {
+ 'published_at'=>
+ {
+ 'label'=>'Published at', 'type'=>'date',
+ 'required'=>true, 'hint'=>'Explanatory text displayed in the back office', 'localized'=>false
+ }
+ }
+ ]
+ }
+ end
+ before { subject.invoke_all }
+
+ it 'generates a content_type file' do
+ File.exists?(content_type_file).should be_true
+ end
+
+ it 'generates a readable yaml file' do
+ expect { YAML.load(File.read content_type_file) }.not_to raise_error
+ end
+
+ it 'creates correct fields' do
+ data = YAML.load(File.read content_type_file)
+ data.should eq expected_data
+ end
+ end
+ end
\ No newline at end of file
spec/generators/generators_helper.rb +2 -0
@@ @@ -0,0 +1,2 @@
+ require_relative '../spec_helper'
+ require 'tmpdir'
\ No newline at end of file
spec/generators/page_spec.rb +45 -0
@@ @@ -0,0 +1,45 @@
+ require_relative 'generators_helper'
+ require 'locomotive/wagon/generators/page'
+
+ describe Locomotive::Wagon::Generators::Page do
+ let(:target_path) { Dir.mktmpdir }
+ before { subject.create_page }
+ after { FileUtils.remove_entry_secure target_path }
+
+ subject { Locomotive::Wagon::Generators::Page.new(args, {}, {}) }
+
+ context 'regular arguments' do
+ let(:args) { [ 'about-us', target_path, [] ] }
+ let(:page_file) { File.join target_path, 'app','views','pages','about-us.liquid' }
+ let(:expected_data) { { 'title'=>'About-us', 'listed'=>true, 'published'=>true } }
+
+ it 'generates a content_type file' do
+ File.exists?(page_file).should be_true
+ end
+
+ it 'generates a readable yaml file' do
+ expect { YAML.load(File.read page_file) }.not_to raise_error
+ end
+
+ it 'creates correct fields' do
+ data = YAML.load(File.read page_file)
+ data.should eq expected_data
+ end
+ end
+
+ context 'multiple locales' do
+ let(:args) { [ 'about-us', target_path, ['fr','en'] ] }
+ let(:page_file_names) { ['about-us.liquid', 'about-us.fr.liquid', 'about-us.en.liquid'] }
+ it 'creates one file per locale , plus default page' do
+ page_file_names.each do |page_file|
+ File.exists?(File.join target_path, 'app','views','pages', page_file).should be_true
+ end
+ end
+
+ it 'translated pages have their own slug' do
+ english_file = File.join target_path, 'app','views','pages', 'about-us.en.liquid'
+ data = YAML.load(File.read english_file)
+ data['slug'].should_not be_empty
+ end
+ end
+ end
\ No newline at end of file
spec/spec_helper.rb +8 -6
@@ @@ -1,15 +1,17 @@
require "locomotive/wagon"
require "rspec"
require "launchy"
- require 'pry'
Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
require file
end
- RSpec.configure do |c|
- c.include Spec::Helpers
- c.before(:all) { remove_logs }
- c.before { reset! }
- c.after { reset! }
+ RSpec.configure do |config|
+ config.include Spec::Helpers
+ config.before(:all) { remove_logs }
+ config.before { reset! }
+ config.after { reset! }
+ config.filter_run focused: true
+ config.run_all_when_everything_filtered = true
+
end
\ No newline at end of file