Problem description:
I setup jasmine for ROR,when i wrote jasmine test-case(i.e 'helloworld.js') which test javascript code(i.e 'hello.js') present inside app/assets/javascripts. When i execute it gives ReferenceError: helloWorld is not defined.one more thing when i put "hello.js" file inside spec/javascript/helper/ the test case gets executed without any error.
ROR project Description:
I setup jasmine for ROR(ruby on rails ) project Following is version info of project: Rails -v 3.2 jasmine 1.2.1 require.js 2.0.6
ROR project directory structure:
blog/ app/ assets/ javascripts/ hello.js application.coffee spec/ javascripts/ helpers/ support/ jasmine.yml helloworld.js spec_helper.rb
/config requirejs.yml Gemfile
**Gemfile:**
group :development, :test do
gem 'rspec-rails'
gem "capybara"
gem "launchy"
gem 'jasmine'
end
hello.js:
function helloWorld() {
return "Hello world!";
}
helloworld.js
describe("Hello world", function() {
it("says hello", function() {
expect(helloWorld()).toEqual("Hello world!");
});
});
requirejs.yml:
shim: bootstrap-alert: deps: [jquery, bootstrap-transition] exports: jQuery.fn.alert bootstrap-button: deps: [jquery] exports: jQuery.fn.button bootstrap-carousel: deps: [jquery, bootstrap-transition] exports: jQuery.fn.carousel bootstrap-collapse: deps: [jquery, bootstrap-transition] exports: jQuery.fn.collapse bootstrap-dropdown: deps: [jquery] exports: jQuery.fn.dropdown bootstrap-modal: deps: [jquery, bootstrap-transition] exports: jQuery.fn.modal bootstrap-popover: deps: [jquery, bootstrap-tooltip] exports: jQuery.fn.popover bootstrap-scrollspy: deps: [jquery] exports: jQuery.fn.scrollspy bootstrap-tab: deps: [jquery, bootstrap-transition] exports: jQuery.fn.tab bootstrap-tooltip: deps: [jquery, bootstrap-transition] exports: jQuery.fn.tooltip bootstrap-transition: deps: [jquery] exports: jQuery.support.transition bootstrap-typeahead: deps: [jquery] exports: jQuery.fn.typeahead backbone: deps: [underscore, jquery] exports: Backbone underscore: exports: _ spin: exports: Spinner jquery.spin: deps: [jquery, spin] exports: jQuery.fn.spin jed: exports: Jed backbone.paginator: deps: [jquery, backbone, underscore] exports: Backbone.Paginator paths: spin: spin-1.2.5 jquery.spin: jquery.spin-0.0.1 jed: jed-0.5.0beta text: text-2.0.1 jade: jade-0.27.0 jade.runtime: jade.runtime-0.27.0 markdown: markdown-0.4.0 backbone.paginator: backbone.paginator-0.1.54.8fcc333d18 fs: compat/fs path: compat/path po: plugins/po j: plugins/j stubModules: - text - po - j excludeShallow: - utils/po2json # find vendor/assets/javascripts/jade-0.27.0 -name '*.js' | grep -v runtime | sed -E 's/.jade[^/]+/(.).js$/ - jade/\1/' - jade/compiler - jade/doctypes - jade/filters - jade/inline-tags - jade/jade - jade/lexer - jade/nodes/attrs - jade/nodes/block-comment - jade/nodes/block - jade/nodes/case - jade/nodes/code - jade/nodes/comment - jade/nodes/doctype - jade/nodes/each - jade/nodes/filter - jade/nodes/index - jade/nodes/literal - jade/nodes/mixin - jade/nodes/node - jade/nodes/tag - jade/nodes/text - jade/parser - jade/self-closing - jade/utils include: # Forcibly include this for compiled Jade templates to run - jade/runtime modules: - name: application - name: locale/application_es locale: es - name: locale/application_en locale: en wrap: true map: markdown: util: compat/noop jade: sass: compat/noop stylus: compat/noop discount: compat/noop markdown-js: compat/noop marked: compat/noop less: compat/noop utils/jade.trans: jade/jade: jade/runtime
jasmine.yml
> # src_files # # Return an array of filepaths relative to src_dir to include before jasmine specs. # Default: [] # # EXAMPLE: # # src_files: # - lib/source1.js # - lib/source2.js # - dist/**/*.js # src_files: - public/javascripts/prototype.js - public/javascripts/effects.js - public/javascripts/controls.js - public/javascripts/dragdrop.js - public/javascripts/application.js - public/javascripts/**/*.js - app/assets/javascripts/*.js # stylesheets # # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs. # Default: [] # # EXAMPLE: # # stylesheets: # - css/style.css # - stylesheets/*.css # stylesheets: - stylesheets/**/*.css # helpers # # Return an array of filepaths relative to spec_dir to include before jasmine specs. # Default: ["helpers/**/*.js"] # # EXAMPLE: # # helpers: # - helpers/**/*.js # helpers: - helpers/**/*.js # spec_files # # Return an array of filepaths relative to spec_dir to include. # Default: ["**/*[sS]pec.js"] # # EXAMPLE: # # spec_files: # - **/*[sS]pec.js # spec_files: - '**/*[sS]pec.js' # src_dir # # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank. # Default: project root # # EXAMPLE: # # src_dir: public # src_dir: # spec_dir # # Spec directory path. Your spec_files must be returned relative to this path. # Default: spec/javascripts # # EXAMPLE: # # spec_dir: spec/javascripts # spec_dir: spec/javascripts
I used following command to setup and run jasmine on ROR
$rails g jasmine:install $rake jasmine your tests are here:
[2012-08-22 21:35:44] INFO WEBrick 1.3.1 [2012-08-22 21:35:44] INFO ruby 1.9.2 (2012-04-20) [i686-linux] [2012-08-22 21:35:44] WARN TCPServer Error: Address already in use - bind(2) [2012-08-22 21:35:44] INFO WEBrick::HTTPServer#start: pid=3210 port=8888