relevance/blue-ridge

patch: automatically create fixutres from templates

Closed this issue · 7 comments

NOTE: For details see commit message in link below

I've ported a gist (http://gist.github.com/148947) from Jonas Nicklas into the blue_ridge + javascript_spec generators.

http://github.com/drnic/blue-ridge/commit/0d425952e40fec35b48e6d2a29c00f92c95b2247 (subsequent commit has patch to README for contributors)

If you're using rspec + pass a relative path to a rails template (e.g. accounts/new.html.rb) then the fixture file will be automatically rendered from the template.

Just run "spec spec/javascripts/accounts_new_spec.rb" (after setting up what data you want for the template).

It's only available for rspec since it uses rspec's view render mechanism.

Added a css() helper to insert css tags into fixtures, like the require() helper inserts <script> tags

http://github.com/drnic/blue-ridge/commit/e085508f296cf5d55473e769a0ef34a20550b5f8

The subsequent commit adds css() stub method to test_runner

I'm doing something similar to generate fixtures but with one additional step - I'm also extracting the javascript from the HTML to generate the javascript file that is included in the spec. Doing this removed duplication that I originally had between the javascript specs and the javascript that was on the HTML page. Code: https://gist.github.com/87926f378ef0c6a72b71

@dan - why did you have JavaScript on the page? :)

(my smart-arse comment assumed you were pulling inline >script> tags; I noticed you're also pulling >script src=''> tags)

Is it better/different to explicitly require those script assets etc from the top of the xxx_spec.js file?

I don't think it makes much of a difference. I like extracting the Javascript because it removes the duplication. Rather than the spec being responsible for knowing which JS files the page needs, the page has that responsibility, and the spec reads it from the page.

But it's common to combine multiple JS files into one, so the re-declaration of JS dependencies should usually be minimal.

This is definitely a direction I want to follow, but I'm a little concerned about requiring Rspec. My goal for the next few months is to allow "plugins" to BlueRidge for letting folks better integrate with Rspec, Cucumber, and even Selenium, without affecting BlueRidge's core functionality. I'm marking this ticket as closed, but will follow up when we get the plugin architecture ready.