-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from nebulab/waiting-for-dev/generator_test_d…
…ependency Remove dependency to test generators
- Loading branch information
Showing
3 changed files
with
41 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'generator_spec' | ||
require 'generators/solidus_starter_frontend/views/override_generator' | ||
|
||
RSpec.describe SolidusStarterFrontend::Views::OverrideGenerator, type: :generator do | ||
destination Rails.root.join('app', 'views', 'spree') | ||
RSpec.describe SolidusStarterFrontend::Views::OverrideGenerator do | ||
include SolidusStarterFrontend::TestingSupport::Generators | ||
|
||
before(:all) do | ||
prepare_destination | ||
def src | ||
SolidusStarterFrontend::Engine.root.join('app', 'views', 'spree') | ||
end | ||
|
||
subject! do | ||
run_generator arguments | ||
def dest | ||
root.join('app', 'views', 'spree') | ||
end | ||
|
||
let(:src) do | ||
::SolidusStarterFrontend::Engine.root.join('app', 'views', 'spree') | ||
def ensure_clean_state | ||
FileUtils.rm_rf dest if File.exist?(dest) | ||
end | ||
|
||
let(:dest) do | ||
Rails.root.join('app', 'views', 'spree') | ||
around(:each) do |example| | ||
ensure_clean_state | ||
example.run | ||
ensure_clean_state | ||
end | ||
|
||
context 'without any arguments' do | ||
let(:arguments) { %w() } | ||
|
||
it 'copies all views into the host app' do | ||
run 'solidus_starter_frontend:views:override' | ||
|
||
expect(src.entries).to match_array(dest.entries) | ||
end | ||
end | ||
|
||
context 'when "products" is passed as --only argument' do | ||
let(:arguments) { %w(--only products) } | ||
|
||
context 'as folder' do | ||
it 'exclusively copies views whose name contains "products"' do | ||
Dir.glob(dest.join("**", "*")).each do |file| | ||
run 'solidus_starter_frontend:views:override --only products' | ||
|
||
Dir.glob(dest.join('**', '*')).each do |file| | ||
next if File.directory?(file) | ||
expect(file.to_s).to match("products") | ||
|
||
expect(file.to_s).to match('products') | ||
end | ||
end | ||
end | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf destination_root | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
spec/support/solidus_starter_frontend/testing_support/generators.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusStarterFrontend | ||
module TestingSupport | ||
# Helper methods to test generators | ||
module Generators | ||
# Run given generator in the dummy application | ||
# | ||
# @param generator [String] Generator to execute as it would be given in | ||
# the command line, including possible options | ||
def run(generator) | ||
`cd #{root} && bin/rails generate #{generator}` | ||
end | ||
|
||
private | ||
|
||
def root | ||
Rails.root | ||
end | ||
end | ||
end | ||
end |