diff --git a/features/configure/approve_dependencies_spec.rb b/features/configure/approve_dependencies_spec.rb index 5b6a33554..4e17e0ace 100644 --- a/features/configure/approve_dependencies_spec.rb +++ b/features/configure/approve_dependencies_spec.rb @@ -21,11 +21,12 @@ specify "include approval detail in reports" do user.execute_command 'license_finder report --format html' - expect(user.html_formatting_of('manual_dep')).to include "approved" + html = user.view_html + expect(html).to be_approved 'manual_dep' - user.in_dep_html("manual_dep") do |manual_dep| - expect(manual_dep).to have_content "Julian" - expect(manual_dep).to have_content "We really need this" + html.in_dep("manual_dep") do |section| + expect(section).to have_content "Julian" + expect(section).to have_content "We really need this" end end end diff --git a/features/configure/name_project_spec.rb b/features/configure/name_project_spec.rb index 012d27308..077b1d23d 100644 --- a/features/configure/name_project_spec.rb +++ b/features/configure/name_project_spec.rb @@ -10,15 +10,16 @@ before { user.create_empty_project } specify "appears in the HTML report" do - user.execute_command 'license_finder project_name add my_proj' + user.execute_command 'license_finder project_name add changed_name' user.execute_command 'license_finder report --format html' - expect(user.html_title).to have_content 'my_proj' + expect(user.view_html).to be_has_title 'changed_name' end specify "defaults to the directory name" do user.execute_command 'license_finder report --format html' - expect(user.html_title).to have_content 'my_app' + + expect(user.view_html).to be_has_title 'my_app' end specify "appears in the CLI" do diff --git a/features/report/html_spec.rb b/features/report/html_spec.rb index 2b5a20596..20f0fb759 100644 --- a/features/report/html_spec.rb +++ b/features/report/html_spec.rb @@ -23,7 +23,7 @@ user.execute_command 'license_finder report --format html' - user.in_dep_html(gem_name) do |section| + user.view_html.in_dep(gem_name) do |section| expect(section.find("a[href='#{gem_attributes[:homepage]}']", text: gem_name)).to be expect(section).to have_content gem_attributes[:license] expect(section).to have_content gem_attributes[:summary] @@ -41,14 +41,13 @@ user.execute_command 'license_finder report --format html' - expect(user.html_formatting_of('gpl_dep')).to include "unapproved" - expect(user.html_formatting_of('mit_dep')).to include "approved" + html = user.view_html + expect(html).to be_unapproved 'gpl_dep' + expect(html).to be_approved 'mit_dep' - user.in_html do |page| - expect(page).to have_content '1 GPL' - action_items = page.find('.action-items') - expect(action_items).to have_content '(GPL)' - expect(action_items).not_to have_content 'MIT' - end + expect(html).to have_content '1 GPL' + action_items = html.find('.action-items') + expect(action_items).to have_content '(GPL)' + expect(action_items).not_to have_content 'MIT' end end diff --git a/features/support/testing_dsl.rb b/features/support/testing_dsl.rb index a9eb27d2c..bf06cb331 100644 --- a/features/support/testing_dsl.rb +++ b/features/support/testing_dsl.rb @@ -1,7 +1,4 @@ -require 'fileutils' -require 'pathname' require 'bundler' -require 'capybara' module LicenseFinder::TestingDSL module Shell @@ -23,6 +20,49 @@ def shell_out(command, allow_failures = false) end end + class User + include Shell + + def run_license_finder + execute_command "license_finder --quiet" + end + + def create_empty_project + EmptyProject.create + end + + def create_ruby_app + RubyProject.create + end + + def execute_command(command) + ::Bundler.with_clean_env do + @output = shell_out("cd #{Paths.app} && bundle exec #{command}", true) + end + end + + def seeing?(content) + @output.include? content + end + + def seeing_line?(content) + seeing_something_like? /^#{Regexp.escape content}$/ + end + + def seeing_something_like?(regex) + @output =~ regex + end + + def receiving_exit_code?(code) + @last_command_exit_status.exitstatus == code + end + + def view_html + HtmlReport.new(@output) + end + end + + require 'pathname' module Paths include Shell extend self @@ -235,62 +275,35 @@ def add_to_bundler(name, options = {}) end end - - class User - include Shell - - def run_license_finder - execute_command "license_finder --quiet" - end - - def create_empty_project - EmptyProject.create - end - - def create_ruby_app - RubyProject.create - end - - def execute_command(command) - ::Bundler.with_clean_env do - @output = shell_out("cd #{Paths.app} && bundle exec #{command}", true) - end - end - - def seeing?(content) - @output.include? content + require 'capybara' + require 'delegate' + class HtmlReport < SimpleDelegator + def initialize(str) + super(Capybara.string(str)) end - def seeing_line?(content) - seeing_something_like? /^#{Regexp.escape content}$/ + def in_dep(dep_name) + result = find("##{dep_name}") + yield result if block_given? + result end - def seeing_something_like?(regex) - @output =~ regex + def approved?(dep_name) + classes_of(dep_name).include? "approved" end - def receiving_exit_code?(code) - @last_command_exit_status.exitstatus == code + def unapproved?(dep_name) + classes_of(dep_name).include? "unapproved" end - def in_html - yield Capybara.string(@output) + def has_title?(title) + find("h1").has_content? title end - def in_dep_html(dep_name) - in_html do |page| - yield page.find("##{dep_name}") - end - end - - def html_formatting_of(dep_name) - in_dep_html(dep_name) do |dep| - dep[:class].split(' ') - end - end + private - def html_title - in_html { |page| page.find("h1") } + def classes_of(dep_name) + in_dep(dep_name)[:class].split(' ') end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b09cf5899..465261b5e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ require 'rspec' require 'webmock/rspec' require 'rspec/its' +require 'fileutils' ENV['test_run'] = true.to_s