{"id":15511816,"url":"https://github.com/testdouble/jasmine-rails","last_synced_at":"2025-10-12T08:32:01.246Z","repository":{"id":46280899,"uuid":"2277989","full_name":"testdouble/jasmine-rails","owner":"testdouble","description":"A Jasmine runner for rails projects that's got you covered in both the terminal and the browser","archived":true,"fork":false,"pushed_at":"2021-11-02T15:30:57.000Z","size":402,"stargazers_count":375,"open_issues_count":23,"forks_count":152,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-07T21:41:33.748Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://rubygems.org/gems/jasmine-rails","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testdouble.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-27T04:52:06.000Z","updated_at":"2025-03-14T19:22:11.000Z","dependencies_parsed_at":"2022-09-03T02:02:03.237Z","dependency_job_id":null,"html_url":"https://github.com/testdouble/jasmine-rails","commit_stats":null,"previous_names":["searls/jasmine-rails"],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/testdouble/jasmine-rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fjasmine-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fjasmine-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fjasmine-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fjasmine-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testdouble","download_url":"https://codeload.github.com/testdouble/jasmine-rails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdouble%2Fjasmine-rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001456,"owners_count":26083102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T09:53:14.492Z","updated_at":"2025-10-12T08:32:00.985Z","avatar_url":"https://github.com/testdouble.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jasmine-rails gem\n\nNOTE: This project is **no longer actively maintained!**\n\n[![Build Status](https://secure.travis-ci.org/searls/jasmine-rails.png)](http://travis-ci.org/searls/jasmine-rails)\n\nThis project is intended to make it a little easier to integrate [Jasmine](https://github.com/pivotal/jasmine/wiki) into your workflow, particularly if you're working in Rails 3.2 or later. (If you're on earlier versions of Rails, I'd suggest directly using the combination of Pivotal's [jasmine gem](https://github.com/pivotal/jasmine-gem) and [jasmine-headless-webkit](http://johnbintz.github.com/jasmine-headless-webkit/).)\n\nBy bundling this gem and configuring your project, you can expect to:\n\n* Be able to run Jasmine specs in a browser (powered by Rails engine mounted into your application)\n* Be able to run Jasmine specs from the command line (powered by\n  [PhantomJS](http://phantomjs.org/))\n* Write specs or source in [CoffeeScript](http://jashkenas.github.com/coffee-script/), leveraging the [asset pipeline](http://railscasts.com/episodes/279-understanding-the-asset-pipeline) to pre-process it\n\n## Installation\n\nFirst, add jasmine-rails to your Gemfile, like so\n\n    group :test, :development do\n      gem 'jasmine-rails'\n    end\n\nNext:\n\n```\n$ bundle install\n```\n\nAnd finally, run the Rails generator:\n\n```\n$ rails generate jasmine_rails:install\n```\n\nThe generator will create the necessary configuration files and mount a test\nrunner to [/specs](http://localhost:3000/specs) so that you can get started\nwriting specs!\n\n## Configuration\n\nConfiguring the Jasmine test runner is done in `spec/javascripts/support/jasmine.yml`.\n\n## Asset Pipeline Support\n\nThe jasmine-rails gem fully supports the Rails asset pipeline which means you can:\n\n* use `coffee_script` or other Javascript precompilers for source or\n  test files\n* use sprockets directives to control inclusion/exclusion of dependent\n  files\n* leverage asset pipeline search paths to include assets from various\n  sources/gems\n\n**If you choose to use the asset pipeline support, many of the `jasmine.yml`\nconfigurations become unnecessary** and you can rely on the Rails asset\npipeline to do the hard work of controlling what files are included in\nyour test suite.\n\n```yaml\n# minimalist jasmine.yml configuration when leveraging asset pipeline\nspec_files:\n  - \"**/*[Ss]pec.{js,coffee}\"\n```\n\nYou can write a spec to test Foo in `spec/javascripts/foo_spec.js`:\n\n```javascript\n// include spec/javascripts/helpers/some_helper_file.js and app/assets/javascripts/foo.js\n//= require helpers/some_helper_file\n//= require foo\ndescribe('Foo', function() {\n  it(\"does something\", function() {\n    expect(1 + 1).toBe(2);\n  });\n});\n```\n\\*As noted above, spec_helper and foo.js must be required in order for foo_spec.js to run.\n\n## Spec files in engine\n\nIf you have an engine mounted in your project and you need to test the engine's javascript files,\nyou can instruct jasmine to include and run the spec files from that engine directory.\n\nGiven your main project is located in `/workspace/my_project` and your engine in `/workspace/engine`,\nyou can add the following in the the `jasmine.yml` file:\n\n```yaml\nspec_dir:\n  - spec/javascripts\n  - ../engine/spec/javascripts\n```\n\n## Include javascript from external source\n\nIf you need to test javascript files that are not part of the assets pipeline (i.e if you have a mobile application\nthat resides outside of your rails app) you can add the following in the the `jasmine.yml` file:\n\n```yaml\ninclude_dir:\n  - ../mobile_app/public/js\n```\n\n## Running from the command line\n\nIf you were to run:\n\n    bundle exec rake spec:javascript\n\nYou'd hopefully see something like:\n\n    Running Jasmine specs...\n\n    PASS: 0 tests, 0 failures, 0.001 secs.\n\nYou can filter execution by passing the `SPEC` option as well:\n\n    bundle exec rake spec:javascript SPEC=my_test\n\nIf you experience an error at this point, the most likely cause is JavaScript being loaded out of order, or otherwise conflicting with other existing JavaScript in your project. See \"Debugging\" below.\n\n## Running from your browser\n\nStartup your Rails server (ex: `bundle exec rails s`), and navigate to the path you have configured in your routes.rb file (ex: [http://localhost:3000/specs](http://localhost:3000/specs)).\nThe Jasmine spec runner should appear and start running your test suite instantly.\n\n## Debugging\n\n### In your browser\n\nIn my workflow, I like to work with specs in the command line until I hit a snag and could benefit from debugging in [Web Inspector](http://www.webkit.org/blog/1091/more-web-inspector-updates/) or [Firebug](http://getfirebug.com/) to figure out what's going on.\n\n### From the command line\n\nEven though they both read from the same config file, it's certainly possible that your specs will pass in the browser and fail from the command line. In this case, you can try to debug or analyze what's going on loading the headless runner.html file into your browser environment. The generated runner.html file is written out to `tmp/jasmine/runner.html` after each run.\n\n### Ajax / XHRs\n\nAs a general rule, Jasmine is designed for unit testing, and as a result real network requests are not appropriate for tests written in Jasmine. (Isolation strategies can include spying on asynchronous libraries and then synchronously testing callback behavior, as [demonstrated in this gist](https://gist.github.com/searls/946704)).\n\nIf your application code issues XHR requests during your test run, please note that **XHR requests for the local filesystem** are blocked by default for most browsers for security reasons.  To debug local XHR requests (for example, if you jasmine-jquery fixtures), you will need to enable local filesystem requests in your browser.\n\nExample for Google Chrome (in Mac OS X):\n    open -a \"Google Chrome\" tmp/jasmine/runner.html --args --allow-file-access-from-files\n\nAgain, it's the opinion of the present author that this shouldn't be necessary in any situation but legacy rescue of an existing test suite. With respect specifically to HTML fixtures, please consider [jasmine-fixture](https://github.com/searls/jasmine-fixture) and [my rationale](http://searls.testdouble.com/posts/2011-12-11-jasmine-fixtures.html) for it.\n\n### Custom Helpers\n\nIf you need to write a custom spec runner template (for example, using requireJS to load components from your specs), you might benefit from\ncustom helper functions.  The controller will attempt to load `JasmineRails::SpecHelper` if it exists. An example:\n\n```ruby\n# in lib/jasmine_rails/spec_helper.rb\nmodule JasmineRails\n  module SpecHelper\n    def custom_function\n      \"hello world\"\n    end\n  end\nend\n```\n\nCreate a custom layout in app/views/layouts/jasmine_rails/spec_runner.html.erb and reference your helper:\n\n```erb\n\u003c%= custom_function %\u003e\n```\n\nIf you wanted to do something like this using [requirejs-rails](https://github.com/jwhitley/requirejs-rails), your helper\nmight look like this:\n\n```ruby\n# in lib/jasmine_rails/spec_helper.rb\nmodule JasmineRails\n  module SpecHelper\n    # Gives us access to the require_js_include_tag helper\n    include RequirejsHelper\n  end\nend\n```\n\nRemove any reference to `src_files` in `spec/javascripts/support/jasmine.yml`, to ensure files aren't loaded prematurely.\n\nCreate your custom layout `app/views/layouts/jasmine_rails/spec_runner.html.erb` like so:\n```erb\n\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta content=\"text/html;charset=UTF-8\" http-equiv=\"Content-Type\"/\u003e\n    \u003ctitle\u003eJasmine Specs\u003c/title\u003e\n\n    \u003c%= stylesheet_link_tag *jasmine_css_files %\u003e\n    \u003c%= requirejs_include_tag %\u003e\n    \u003c%= javascript_include_tag *jasmine_js_files %\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"jasmine_content\"\u003e\u003c/div\u003e\n    \u003c%= yield %\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\n```\n\nUse require with a callback to load your components:\n\n```coffeescript\n\ndescribe 'test my module', -\u003e\n  require ['my/module'], (Module) -\u003e\n    it 'does something', -\u003e\n      expect(Module.method).toEqual 'something'\n```\n\n### Custom Reporter\n\nYou can configure custom reporter files to use when running from the\ncommand line in `jasmine.yml`:\n\n```yml\nreporters:\n  cool-reporter:\n    - \"cool-reporter.js\"\n  awesome-reporter:\n    - \"awesome-part-1.js\"\n    - \"awesome-part-2.js\"\n```\n\nThen, specify which reporters to use when you run the rake task:\n\n```\nREPORTERS='cool-reporter,awesome-reporter' rake spec:javascripts\n```\n\nThe console reporter shipped with jasmine-rails will be used by\ndefault, and you can explicitly use it by the name `console`.\n\nSee [jasmine-junitreporter][j-junit] for an example with JUnit output.\n\n[j-junit]: https://github.com/shepmaster/jasmine-junitreporter-gem\n\n## PhantomJS binary\n\nBy default the [PhantomJS gem](https://github.com/colszowka/phantomjs-gem) will\nbe responsible for finding and using an appropriate version of PhantomJS. If\nhowever, you wish to manage your own phantom executable you can set:\n\n```yml\nuse_phantom_gem: false\n```\n\nThis will then try and use the `phantom` executable on the current `PATH`.\n\n## PhantomJS command-line options\n\nIf you want to pass command-line options to phantomjs executable, you can set:\n\n```yml\nphantom_options: --web-security=no --debug=yes\n```\n\nThis will pass everything defined on `phantom_options` as\n[options](http://phantomjs.org/api/command-line.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdouble%2Fjasmine-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestdouble%2Fjasmine-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdouble%2Fjasmine-rails/lists"}