Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Multiple Environments/Suites? #24

Open
andyl opened this issue Nov 10, 2011 · 8 comments
Open

Question: Multiple Environments/Suites? #24

andyl opened this issue Nov 10, 2011 · 8 comments

Comments

@andyl
Copy link
Contributor

andyl commented Nov 10, 2011

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
Copy link
Contributor Author

andyl commented Nov 13, 2011

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
Copy link
Contributor

dnagir commented Nov 17, 2011

This would definitely be useful! +1

@mech
Copy link

mech commented Dec 14, 2011

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
Copy link
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
Copy link
Contributor

dnagir commented Jun 29, 2012

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
Copy link
Contributor Author

andyl commented Jun 29, 2012

+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
Copy link
Contributor Author

andyl commented Aug 31, 2012

@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.

@mltsy
Copy link

mltsy commented Nov 1, 2012

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
Projects
None yet
Development

No branches or pull requests

5 participants