Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Question: Multiple Environments/Suites? #24

Open
andyl opened this Issue · 8 comments

5 participants

@andyl

From the Readme, it looks like you can establish only one jasmine rice environment:

- CoffeeScript: spec/javascripts/spec.js.coffee
- StyleSheet: spec/javascripts/spec.css
- Goto: http://localhost:3000/jasmine

I'd like to organize my tests into separate suites. Is there a way to establish multiple environments with jasminerice? Something like this in routes.rb:

mount Jasminerice::Engine => "/suite1", :spec => "spec/javascripts/suite1.js.coffee"
mount Jasminerice::Engine => "/suite2", :spec => "spec/javascripts/suite2.js.coffee"

Tx, Andy

@andyl

Looks like the answer is 'no' - you can only establish one jasminerice environment, which loads all the test libraries from spec/javascripts/spec.js.coffee.

FYI - I'd like to establish multiple environments for two reasons:

  • Some of my pages are for mobile devices, and use zepto instead of jquery. You can't load jasmine-jquery and jasmine-zetpo both in the same test environment
  • I'd like to create a stripped-down test suite that my end-users can run in production. It would run operations on a mobile device to test compatibility, checks to see that firewall ports are open, etc.
@dnagir

This would definitely be useful! +1

@mech

I am using Rails 3.1.3 for mobile application with Backbone and using Jamsine for BDD. However is using Zepto. Will there be support for Zepto in the pipeline? +1 for it

@bradphelan
Owner

Actually it would be pretty easy to load multiple environments.

http://localhost:3000/jasmine/:environment

In the controller app/controllers/jasminerice/spec_controller.rb we could add

def get
    @specenv = params[:environment]
    render :index
end

and change app/views/jasminerice/spec/index.html.haml to something like

%html
  %head
    %title Jasmine Spec Runner
    = stylesheet_link_tag "jasmine"
    = stylesheet_link_tag "spec"
    = javascript_include_tag "jasminerice"
    - if @environment
        = javascript_include_tag @environment 
    - else
        = javascript_include_tag "spec"
    = csrf_meta_tags
  %body

Please some feedback on the idea before I try to implement this or somebody is free to implement and provide feedback and a pull request.

@dnagir

Can we rename the question so that "environment" isn't used here since it confuses the hell out of it. It should be "suite" I believe.

@andyl

+1 for renaming 'environment' to 'suite'. My first reaction upon re-reading my own question was to think about development/test/production environments - and that is an incorrect way to think about this issue. Suites is a better term.

@andyl

@bradphelan thanks for your suggestions. I followed your advice and everything works. Here is my solution:

In routes.rb:

    if %w(development test).include? Rails.env
      mount Jasminerice::Engine => "/jasmine/:suite"
    end

In app/controllers/jasminerice/spec_controller.rb:

    def index
      @specenv = params[:suite].try(:concat, "_spec") || "spec"
    end

In app/views/jasminerice/spec/index.html.haml:

    %html
      %head
        %title Jasmine Spec Runner
        = stylesheet_link_tag "jasmine"
        = stylesheet_link_tag "spec"
        = javascript_include_tag "jasminerice"
        = javascript_include_tag @specenv
        = csrf_meta_tags
      %body

Once this was done, I created three test suites: spec.js, browser_spec.js and mobile_spec.js. Note that when using multiple suites, you can no longer use the pipeline directive #=require_tree ./. Instead, you have to call out the test directories one by one. For example:

In mobile_spec.js:

#=require_tree ./mobile_specs
#=require_tree ./more_mobile_specs

In browser_spec.js:

#=require_tree ./browser_specs
#=require_tree ./more_browser_specs

Then I ran each suite:

    http://localhost:3000/jasmine
    http://localhost:3000/jasmine/mobile
    http://localhost:3000/jasmine/browser

Everything worked perfectly. I'll send you a pull request with my changes.

@andyl andyl referenced this issue from a commit in andyl/jasminerice
@andyl andyl Update app/views/jasminerice/spec/index.html.haml
Changed "spec" to @specenv in order to support multiple test suites.  See Issue #24 for more info.
4b4e4e8
@andyl andyl referenced this issue from a commit in andyl/jasminerice
@andyl andyl Update app/controllers/jasminerice/spec_controller.rb
Added @specenv variable to support multiple environments.  See Issue #24 for more info.
c8e7b31
@mltsy

Very excited about this update! We just may start unit testing the javascript in our Rails app! ;) Is this now in the current release, or how soon will this feature be released? (Looks like the issue is still open, so I'm not sure what that means)

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.