From 1b4b51236a6b58e818fe0773c0b8d5933cb68c80 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 19 Sep 2016 16:59:14 +0530 Subject: [PATCH 1/4] add theme-gem feature for bonafide theme gems this cucumber feature follows the likely steps a theme designer would take to build a Rubygem of his theme starting from the scaffolding generated by `jekyll new-theme` command and further checks if the gem built actually has the files he planned to include. --- features/step_definitions.rb | 26 ++++++++++++++++++++++++++ features/support/helpers.rb | 8 ++++++++ features/theme_gem.feature | 31 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 features/theme_gem.feature diff --git a/features/step_definitions.rb b/features/step_definitions.rb index ffe3fff5..e993b4f9 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -156,6 +156,31 @@ end # +When(%r!^I run gem(.*)$!) do |args| + run_rubygem(args) + if args.include?("--verbose") || ENV["DEBUG"] + $stderr.puts "\n#{jekyll_run_output}\n" + end +end + +# + +When(%r!^I run git add .$!) do + run_in_shell("git", "add", ".") +end + +# + +When(%r!^I decide to build the theme gem$!) do + Dir.chdir(Paths.theme_gem_dir) + gemspec = "my-cool-theme.gemspec" + File.write(gemspec, File.read(gemspec).sub("TODO: ", "")) + File.new("_includes/blank.html", "w") + File.new("_sass/blank.scss", "w") +end + +# + When(%r!^I change "(.*)" to contain "(.*)"$!) do |file, text| File.open(file, "a") do |f| f.write(text) @@ -179,6 +204,7 @@ Then(%r!^the (.*) directory should +(not )?exist$!) do |dir, negative| end # + Then(%r!^I should (not )?see "(.*)" in "(.*)"$!) do |negative, text, file| step %(the "#{file}" file should exist) regexp = Regexp.new(text, Regexp::MULTILINE) diff --git a/features/support/helpers.rb b/features/support/helpers.rb index 0d809bca..e5d17bb2 100644 --- a/features/support/helpers.rb +++ b/features/support/helpers.rb @@ -8,6 +8,8 @@ class Paths SOURCE_DIR = Pathname.new(File.expand_path("../..", __dir__)) def self.test_dir; source_dir.join("tmp", "jekyll"); end + def self.theme_gem_dir; source_dir.join("tmp", "jekyll", "my-cool-theme"); end + def self.output_file; test_dir.join("jekyll_output.txt"); end def self.status_file; test_dir.join("jekyll_status.txt"); end @@ -88,6 +90,12 @@ end # +def run_rubygem(args) + run_in_shell("gem", *args.strip.split(" ")) +end + +# + def run_jekyll(args) args = args.strip.split(" ") # Shellwords? process = run_in_shell("ruby", Paths.jekyll_bin.to_s, *args, "--trace") diff --git a/features/theme_gem.feature b/features/theme_gem.feature new file mode 100644 index 00000000..b79d9c0b --- /dev/null +++ b/features/theme_gem.feature @@ -0,0 +1,31 @@ +Feature: Building Theme Gems + As a hacker who likes to share my expertise + I want to be able to make a bonafide rubygem off my theme + In order to share my awesome style skillz with other Jekyllites + + Scenario: Generating a new Jekyll Theme + When I run jekyll new-theme my-cool-theme + Then I should get a zero exit status + And the my-cool-theme directory should exist + + Scenario: Checking if a bonafide Theme gem will be built from generated scaffolding + When I run jekyll new-theme my-cool-theme + Then I should get a zero exit status + And the my-cool-theme directory should exist + When I decide to build the theme gem + Then I should get a zero exit status + When I run git add . + Then I should get a zero exit status + When I run gem build my-cool-theme.gemspec + Then I should get a zero exit status + And the "./my-cool-theme-0.1.0.gem" file should exist + When I run gem unpack my-cool-theme-0.1.0.gem + Then I should get a zero exit status + And the my-cool-theme-0.1.0 directory should exist + And the "my-cool-theme-0.1.0/_layouts/default.html" file should exist + And the "my-cool-theme-0.1.0/_includes/blank.html" file should exist + And the "my-cool-theme-0.1.0/_sass/blank.scss" file should exist + And the my-cool-theme-0.1.0/.git directory should not exist + And the "my-cool-theme-0.1.0/.gitignore" file should not exist + And the "my-cool-theme-0.1.0/Gemfile" file should not exist + And the "my-cool-theme-0.1.0/my-cool-theme.gemspec" file should not exist From 1fb4dce2f5b1d9618ef737469a3477eb1cbf93ef Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 23 Sep 2016 23:21:10 +0530 Subject: [PATCH 2/4] add a step to check contents in assets directory --- features/step_definitions.rb | 2 ++ features/theme_gem.feature | 1 + 2 files changed, 3 insertions(+) diff --git a/features/step_definitions.rb b/features/step_definitions.rb index e993b4f9..7d490cda 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -177,6 +177,8 @@ When(%r!^I decide to build the theme gem$!) do File.write(gemspec, File.read(gemspec).sub("TODO: ", "")) File.new("_includes/blank.html", "w") File.new("_sass/blank.scss", "w") + FileUtils.mkdir_p("assets/css") + File.new("assets/css/blank.scss", "w") end # diff --git a/features/theme_gem.feature b/features/theme_gem.feature index b79d9c0b..d36c71ac 100644 --- a/features/theme_gem.feature +++ b/features/theme_gem.feature @@ -25,6 +25,7 @@ Feature: Building Theme Gems And the "my-cool-theme-0.1.0/_layouts/default.html" file should exist And the "my-cool-theme-0.1.0/_includes/blank.html" file should exist And the "my-cool-theme-0.1.0/_sass/blank.scss" file should exist + And the "my-cool-theme-0.1.0/assets/css/blank.scss" file should exist And the my-cool-theme-0.1.0/.git directory should not exist And the "my-cool-theme-0.1.0/.gitignore" file should not exist And the "my-cool-theme-0.1.0/Gemfile" file should not exist From 87a03f6c1a2c78628e1e9d39c1b04c5d7a95e5de Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 30 Sep 2016 15:23:08 +0530 Subject: [PATCH 3/4] replace zero exit status steps --- features/step_definitions.rb | 23 ++++++++++++++++++++++- features/theme_gem.feature | 15 +++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/features/step_definitions.rb b/features/step_definitions.rb index 7d490cda..bf6883af 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -166,7 +166,7 @@ end # When(%r!^I run git add .$!) do - run_in_shell("git", "add", ".") + run_in_shell("git", "add", ".", "--verbose") end # @@ -264,6 +264,27 @@ end # +Then(%r!^I should get an updated git index$!) do + index = %w( + .gitignore + Gemfile + LICENSE.txt + README.md + _includes/blank.html + _layouts/default.html + _layouts/page.html + _layouts/post.html + _sass/blank.scss + assets/css/blank.scss + my-cool-theme.gemspec + ) + index.each do |file| + expect(jekyll_run_output).to match file + end +end + +# + Then(%r!^I should get a zero exit(?:\-| )status$!) do step %(I should see "EXIT STATUS: 0" in the build output) end diff --git a/features/theme_gem.feature b/features/theme_gem.feature index d36c71ac..875a8568 100644 --- a/features/theme_gem.feature +++ b/features/theme_gem.feature @@ -10,18 +10,17 @@ Feature: Building Theme Gems Scenario: Checking if a bonafide Theme gem will be built from generated scaffolding When I run jekyll new-theme my-cool-theme - Then I should get a zero exit status - And the my-cool-theme directory should exist + Then the my-cool-theme directory should exist When I decide to build the theme gem - Then I should get a zero exit status + Then the "_includes/blank.html" file should exist + Then the "_sass/blank.scss" file should exist + Then the "assets/css/blank.scss" file should exist When I run git add . - Then I should get a zero exit status + Then I should get an updated git index When I run gem build my-cool-theme.gemspec - Then I should get a zero exit status - And the "./my-cool-theme-0.1.0.gem" file should exist + Then the "./my-cool-theme-0.1.0.gem" file should exist When I run gem unpack my-cool-theme-0.1.0.gem - Then I should get a zero exit status - And the my-cool-theme-0.1.0 directory should exist + Then the my-cool-theme-0.1.0 directory should exist And the "my-cool-theme-0.1.0/_layouts/default.html" file should exist And the "my-cool-theme-0.1.0/_includes/blank.html" file should exist And the "my-cool-theme-0.1.0/_sass/blank.scss" file should exist From f636067661f2cad2c9c97e5526b3631c2e265dd2 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 30 Sep 2016 15:34:46 +0530 Subject: [PATCH 4/4] remove 'css' subdirectory from assets folder --- features/step_definitions.rb | 5 ++--- features/theme_gem.feature | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/features/step_definitions.rb b/features/step_definitions.rb index bf6883af..b57f5bb8 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -177,8 +177,7 @@ When(%r!^I decide to build the theme gem$!) do File.write(gemspec, File.read(gemspec).sub("TODO: ", "")) File.new("_includes/blank.html", "w") File.new("_sass/blank.scss", "w") - FileUtils.mkdir_p("assets/css") - File.new("assets/css/blank.scss", "w") + File.new("assets/blank.scss", "w") end # @@ -275,7 +274,7 @@ Then(%r!^I should get an updated git index$!) do _layouts/page.html _layouts/post.html _sass/blank.scss - assets/css/blank.scss + assets/blank.scss my-cool-theme.gemspec ) index.each do |file| diff --git a/features/theme_gem.feature b/features/theme_gem.feature index 875a8568..c46d37e0 100644 --- a/features/theme_gem.feature +++ b/features/theme_gem.feature @@ -14,7 +14,7 @@ Feature: Building Theme Gems When I decide to build the theme gem Then the "_includes/blank.html" file should exist Then the "_sass/blank.scss" file should exist - Then the "assets/css/blank.scss" file should exist + Then the "assets/blank.scss" file should exist When I run git add . Then I should get an updated git index When I run gem build my-cool-theme.gemspec @@ -24,7 +24,7 @@ Feature: Building Theme Gems And the "my-cool-theme-0.1.0/_layouts/default.html" file should exist And the "my-cool-theme-0.1.0/_includes/blank.html" file should exist And the "my-cool-theme-0.1.0/_sass/blank.scss" file should exist - And the "my-cool-theme-0.1.0/assets/css/blank.scss" file should exist + And the "my-cool-theme-0.1.0/assets/blank.scss" file should exist And the my-cool-theme-0.1.0/.git directory should not exist And the "my-cool-theme-0.1.0/.gitignore" file should not exist And the "my-cool-theme-0.1.0/Gemfile" file should not exist