Skip to content

Commit

Permalink
Actually get dummy test app running properly and passing feature tests
Browse files Browse the repository at this point in the history
* Configure dummy test all with the test controller/views for demo under test
* properly set up sprockets for bootstrap 4 to include JS in dummy app
* properly get all dummy app dependencies set up -- this is the weirdest most confusing part
  * dependencies are actually listed in .gemspec as development dependencies
  * but may also need to be require'd in application.rb, which would normally happen automatically if they were
    in a real Gemfile

* We give up on being able to test both bootstrap 3 and 4 -- that's not really tenable with the dummy app approach, since they use different gems entirely, and different local CSS files. We only test bootstrap 4 now.

* Actually enable the formerly disabled feature tests!
  • Loading branch information
jrochkind committed Jun 16, 2022
1 parent d18350a commit d7db9f6
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 12 deletions.
12 changes: 8 additions & 4 deletions Gemfile
Expand Up @@ -9,12 +9,17 @@ group :development, :test do
gem 'pry-byebug' unless ENV['CI']
end

# We allow testing under multiple versions of Rails by setting ENV RAILS_VERSION,
# used in CI, can be used locally too. Make sure to delete your Gemfile.lock after
# changing a local RAILS_VERSION
# == Extra dependencies for dummy test app ==
#
# Extra dependencies for dummy test app are in .gemspec as a development dependency
# where possible. But when dependencies vary for different versions
# of Rails, rails-version-specific dependencies are here, behind conditionals, for now.
#
# TODO switch to use appraisal gem instead, encapsulating these different additional
# dependencies per Rails version, as well as method of choosing operative rails version.
#
# We allow testing under multiple versions of Rails by setting ENV RAILS_VERSION,
# used in CI, can be used locally too.

# Set a default RAILS_VERSION so we make sure to get extra dependencies for it...

Expand Down Expand Up @@ -44,7 +49,6 @@ if ENV['RAILS_VERSION']
gem "mail", ">= 2.8.0.rc1"
when /^6\.0\./
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
when /^5\.[12]\./
gem 'sass-rails', '~> 5.0'
gem 'sprockets', '~> 3.7'
Expand Down
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -284,9 +284,7 @@ Or individually, `bundle exec rubocop`, `bundle exec rspec`.

You can test with different versions of rails by setting ENV variable `RAILS_VERSION` to a specific version like `"6.1.2"` or `"7.0.0"`, perhaps by `export RAILS_ENV=7.0.0` to set it in your shell session.

Tests by default will be run with bootstrap-4 integration. You can test with bootstrap-3 by setting ENV varaible `TEST_BOOTSTRAP=3`.

After changing `RAILS_VERSION` or `TEST_BOOTSTRAP` you may have to run `rm Gemfile.lock` and `bundle install` again. If you get a `Bundler could not find compatible versions...` error, for instance.
After changing `RAILS_VERSION` you may have to run `rm Gemfile.lock` and `bundle install` again. If you get a `Bundler could not find compatible versions...` error, for instance.

# Help

Expand Down
8 changes: 8 additions & 0 deletions browse-everything.gemspec
Expand Up @@ -29,20 +29,28 @@ Gem::Specification.new do |spec|
spec.add_dependency 'signet', '~> 0.8'
spec.add_dependency 'typhoeus'

# Development dependencies include dependencies necessary for running
# the dummy test app at ./spec/dummy_test_app

spec.add_development_dependency 'bixby', '~> 5.0'
spec.add_development_dependency 'bootstrap', "~> 4.0" # we do not support bootstrap 5
spec.add_development_dependency 'bundler', '>= 1.3'
spec.add_development_dependency 'capybara'
spec.add_development_dependency 'factory_bot_rails'
spec.add_development_dependency 'jquery-rails'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'puma'
spec.add_development_dependency 'rails-controller-testing'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rspec-its'
spec.add_development_dependency 'rspec-rails'
spec.add_development_dependency 'rspec_junit_formatter'
spec.add_development_dependency 'rubocop-rspec'
spec.add_development_dependency 'sass-rails'
spec.add_development_dependency 'selenium-webdriver'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'turbolinks'
spec.add_development_dependency 'webdrivers'
spec.add_development_dependency 'webmock'
end
5 changes: 2 additions & 3 deletions spec/dummy_test_app/app/assets/config/manifest.js
@@ -1,4 +1,3 @@

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link application.css
//= link application.js
12 changes: 12 additions & 0 deletions spec/dummy_test_app/app/assets/javascripts/application.js
Expand Up @@ -10,4 +10,16 @@
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//

// We want to test with turbolinks, which our code also requires rails-ujs to deal with:

//= require rails-ujs
//= require turbolinks

// Actual stack required for current browse-everything JS

//= require jquery3
//= require bootstrap
//= require browse_everything

//= require_tree .
Expand Up @@ -13,3 +13,6 @@
*= require_tree .
*= require_self
*/

@import "bootstrap";
@import "browse_everything/browse_everything_bootstrap4";
11 changes: 11 additions & 0 deletions spec/dummy_test_app/app/controllers/file_handler_controller.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class FileHandlerController < ApplicationController
def index; end

def main; end

def update
render json: params[:selected_files].to_json
end
end
10 changes: 10 additions & 0 deletions spec/dummy_test_app/app/views/file_handler/index.html.erb
@@ -0,0 +1,10 @@
<div class="panel panel-default">
<div class="panel-body">
<a href="main" class="btn btn-large btn-primary" role="button">Enter Test App (Turbolinks)</a>

<%# this doesn't REALLY test no Turbolinks, as there will still be a `window.Turbolinks` object,
and a `turbolinks:load` event. It just tests as if the page we are navigating to were the FIRST
page loaded under turbolinks %>
<a href="main" class="btn btn-large btn-primary" role="button" data-turbolinks="false" data-no-turbolink>Enter Test App (No Turbolinks)</a>
</div>
</div>
25 changes: 25 additions & 0 deletions spec/dummy_test_app/app/views/file_handler/main.html.erb
@@ -0,0 +1,25 @@
<div class="jumbotron">
<h1>Welcome!</h1>

<p>Please click the button below to start pickin' files!</p>

<%= form_tag('/file', id: 'main_form', method: 'post') do %>
<%= button_tag("Browse", type: 'button', class: 'btn btn-large btn-success', id: "browse-btn",
'data-toggle' => 'browse-everything', 'data-route' => browse_everything_engine.root_path,
'data-target' => '#main_form') %>
<%= button_tag("Submit", type: 'submit', class: 'btn btn-large btn-primary', id: "submit-btn") %>
<% end %>

<p id="status">0 items selected</p>

<script>
$(document).on('turbolinks:load', function() {
// Have to make sure onReady is ALSO passed, in case it's first load.
$(function() {
$('#browse-btn').browseEverything()
.done(function(data) { $('#status').html(data.length.toString() + " items selected") })
.cancel(function() { window.alert('Canceled!') });
});
});
</script>
</div>
8 changes: 8 additions & 0 deletions spec/dummy_test_app/config/application.rb
Expand Up @@ -5,6 +5,14 @@
Bundler.require(*Rails.groups)
require "browse_everything"

# Since we don't actually have an app-specific Gemfile,
# Some development dependencies listed in .gemspec need to be required here,
# that would ordinarily be auto-required by being in a Gemfile instead of gemspec.
require 'bootstrap'
require 'sprockets/railtie'
require 'jquery-rails'
require 'turbolinks'

module Dummy
class Application < Rails::Application
# ~Initialize configuration defaults for originally generated Rails version.~
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy_test_app/config/routes.rb
@@ -1,4 +1,9 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
mount BrowseEverything::Engine => '/browse'

# Custom actions we use for feature testing
root :to => "file_handler#index"
get '/main', :to => "file_handler#main"
post '/file', :to => "file_handler#update"
end
2 changes: 1 addition & 1 deletion spec/features/select_files_spec.rb
Expand Up @@ -7,7 +7,7 @@

shared_examples 'browseable files' do
# This is a work-around until the support for Webpacker is resolved
xit 'selects files from the filesystem' do
it 'selects files from the filesystem' do
click_button('Browse')
wait_for_ajax

Expand Down
2 changes: 1 addition & 1 deletion spec/features/test_compiling_stylesheets_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

describe 'Compiling the stylesheets', type: :feature, js: true do
xit 'does not raise errors' do
it 'does not raise errors' do
visit '/'
expect(page).not_to have_content 'Sass::SyntaxError'
end
Expand Down

0 comments on commit d7db9f6

Please sign in to comment.