Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to setup my Rails-Angular project to provide JS tests. I have tried almost everything what I have found in Google:

but I failed with all of them. I'm looking for way to run unit and e2e tests in most painless way (it can be in Guard or Karma, I don't care, but it must run it automatically in background).

Have anyone of you some nice article with nice example how to achieve this? In my research I have found this, but IMHO it is example how to NOT do this.

My actual Gemfile:

source 'https://rubygems.org'

# Use Ruby 1.9.3 instead default Heroku's 1.9.2
# for development I suggest https://gist.github.com/1688857
ruby '1.9.3'

gem 'rails', '3.2.12'

# Use PostgreSQL, which is quite awesome, fast and easy
gem 'pg'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', '~> 3.2.3'
  gem 'bootstrap-sass', '~> 2.3.1'

  # I heard that you like Compass
  gem 'compass'

  # Angular.js
  gem 'angularjs-rails'
  gem 'angularjs-rails-resource'
  gem 'angular-ui-rails'

  # Assets should be minified before production
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# Serve static pages like a boss
gem 'high_voltage'

# Some user management will be nice
gem 'devise' # User management
# gem 'cancan' # And they privileges

# To use Jbuilder templates for JSON
gem 'jbuilder'

# Be fast and deadly as Puma
#gem 'puma'

# We need also some administration panel, don't we?
gem 'rails_admin'

# Some helpers
gem 'andand'

group :development do
  # IRb is ugly. Use Pry for the God's sake
  gem 'pry-rails'

  # Deploy with Capistrano
  # gem 'capistrano'
  # or Vlad the Deployer
  # gem 'vlad'

  # Why bother yourself with rerunning tests? Use Guard
  gem 'guard'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'guard-livereload'
  gem 'guard-jasmine'
  gem 'rb-fsevent', require: false
  gem 'rb-inotify', require: false

  # Who like ugly error pages? We don't.
  gem 'better_errors'
  gem 'binding_of_caller'

  # Prettier documentation
  gem 'yard'
end

group :development, :test do
  # Use RSpec for testing
  gem 'rspec-rails', '~> 2.12.0'

  # Test JS using Jasmine
  gem 'jasmine'
  gem 'jasmine-headless-webkit'

  # Some DB table generator
  gem 'factory_girl_rails', '~> 4.1.0'

  # And fake data generator
  gem 'ffaker'
end

group :test do
  # Some Gherkins will be also good (to vodka of course)
  gem 'turnip', '~> 1.1.0'

  # Aww, an of course some web browser will be also apprised
  gem 'capybara', '~> 2.0.1'

  # Clean DB after tests
  gem 'database_cleaner'

  # Some nice matchers
  gem 'shoulda-matchers'

  # Extend your mocks
  gem 'bourne', '~> 1.2.1'

  # Coverage reports will be nice
  gem 'simplecov', require: false
end

PS: It would be nice if I can create coverage reports in simple way.

share|improve this question
"but it must run it automatically in background" - we created test runners that ran off Grunt for our Angular project and these created coverage reports and xUnit outputs for CI (such as Jenkins); so does it matter that you have to run these tests from a Gemfile or can you throw some nodejs into the mix? – Ahmed Nuaman 9 hours ago
It will be nice to have it in Gemfile to integrate that with Guard, but I'm not forced to that. Maybe even better will it be if I separate frontend tests from backend tests. So Grunt/Karma option is also nice. But I also want to have all tests in spec/ directory (if it is possible). – Łukasz Niemier 8 hours ago

This question had a bounty worth +100 reputation from Łukasz Niemier that ended 6 hours ago; grace period ends in 17 hours

This question has not received enough attention.

1 Answer

You may have some luck checking out the angular boilerplate project it uses grunt as the build system which I realise is not ruby in anyway, however I think when trying to test things with angular your only hope is to go the nodejs/karma route.

This setup watches for changes in your code and runs the tests. However in my limited experience I haven't been able to get it to show the results of the test run. I am not sure whether I am doing something wrong or if it is not supported.

Anyway hope this helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.