Skip to content
This repository has been archived by the owner. It is now read-only.

Setup testing for gem using dummy application #1

merged 21 commits into from May 20, 2014

Setup testing for gem using dummy application #1

merged 21 commits into from May 20, 2014


Copy link

@fofr fofr commented May 16, 2014

  • Test JavaScript using Jasmine
  • Test template includes with Capybara/RSpec
    • Symlink dummy specs with spec directory for smoother RSpec testing
  • Make bundle exec rake default to running all tests
  • Make the dummy app (spec/dummy) resemble an app that's using the gem
    • Include govuk_admin_template js and css, and incorporate template
  • Include jQuery dependency — Bootstrap depends on jQuery being present within the template

Dummy application when running:

screen shot 2014-05-16 at 15 40 56

fofr added 10 commits May 15, 2014
* Generated from running `rails plugin new …`
* Drop test-unit
* Generate spec following instructions from:
* Create a symlink from the dummy app to the plugin spec directory
* Running Rspec from root will pick up specs from the dummy app as well
* Run `rails g jasmine:install`
* Confirm that images are being served
* Confirm that the javascript is compiled
* Bundle up to be included in the govuk_admin_template js include
* Bootstrap is dependent on jQuery, it’s necessary
* Remove dummy app dependencies on jQuery
* Include admin styles and js
* Render the admin template
* Use a simple welcome controller and template
* Provide tests for what should be passed to an app’s layout
Running jasmine from root prevents the spec files from being compiled
through the asset pipeline. The way the jasmine gem works doesn’t play
well with engines, it uses a lot of non-public APIs.

By proxying the rake task through to the dummy app we fool jasmine into
thinking it’s testing a full rails app, and we get the test and test
results we need.

This comment has been minimized.

Copy link

@rgarner rgarner commented on spec/govuk_admin_template_test.rb in ecf0796 May 16, 2014

TestUnit and RSpec?

This comment has been minimized.

Copy link
Contributor Author

@fofr fofr replied May 16, 2014

This is deleted in a later commit. :)

fofr and others added 8 commits May 16, 2014
* Prove that the specs are using compiled assets as expected
* Reduce noise and simplify dummy application
* Followed instructions from
* Running bundle from within a rake task caused the jasmine:ci task to
fail unexpectedly
* Loading the dummy_app tasks within a namespace and calling the
jasmine tests through that works as expected
It doesn't affect any users of the gem itself, but it makes working on the gem
more predictable.
They're already in the gemspec.
The number of combinations of dependencies was so large that Bundler was taking
a very long time (forever?) to resolve the dependencies. Pinning the dev
dependencies doesn't affect users of the gem.

Also require Rails 3.2 and above - not strictly required in this change, but
all of our apps are on 3.2 and above anyway.
//= require govuk_admin_template

This comment has been minimized.


alext May 19, 2014

I think it would be good to load in the template assets in the template layout instead of relying on the consuming applications including them in their application.js/css files. This is the pattern we've used in govuk_template.

This comment has been minimized.


fofr May 19, 2014
Author Contributor

As discussed, the Javascript has been included here: 14b5d41

* Don’t require applications to put javascript in application.js, setup
* Leads to one more HTTP request on first hit, but subsequent cache
benefits afterwards

This comment has been minimized.

Copy link

@alext alext commented on 14b5d41 May 19, 2014

I think you'll need to add govuk_admin_template.js to

app.config.assets.precompile += %w(lte-ie8.js)

This comment has been minimized.

Copy link
Contributor Author

@fofr fofr replied May 19, 2014

Ahh yes, good spot. I've fixed in 2bba7b4 and also renamed the javascript file to be hyphenated (see e70dba6)

fofr added 2 commits May 19, 2014
* Be consistent in naming patterns, both internally and with other
* Hyphens are common practice in HTML
alext added a commit that referenced this pull request May 20, 2014
Setup testing for gem using dummy application
@alext alext merged commit 014b701 into master May 20, 2014
@alext alext deleted the gem-testing branch May 20, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.