Coder Social home page Coder Social logo

johnnyshields / ember-konacha-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kristianmandrup/ember-konacha-rails

0.0 3.0 0.0 173 KB

Generate Konacha spec infrastructure for your Ember-Rails apps

License: MIT License

Ruby 77.28% CoffeeScript 9.24% JavaScript 13.48%

ember-konacha-rails's Introduction

Ember Konacha generators for Rails

Generators to help setup an ember-rails app with konacha testing.

PS: Still young and under development... Please help improve it :)

What?

This gem has the stated goal of making it easy to setup a good testing infrastructure for testing your Ember-Rails apps.

An install generator is included for initial infrastructure setup!

Configures your Ember app with Konacha using a Javascript driver (poltergeist for PhantomJS by default). Adds the basic Konacha infrastructure so you can start writing tests/specs.

Can generate Konacha spec-skeletons for:

  • models
  • controllers
  • views
  • helpers

Please help provide more skeleton generators or improve the existing ones!!! :)

More generators

You can find more generators/scaffolders as part of ember-tools

ember-i18n-rails or here. Includes generators to configure and manage i18n with Ember and Rails.

Other Ember-Rails tools

Installation

Add this line to your application's Gemfile:

gem 'ember-konacha-rails', github: 'kristianmandrup/ember-konacha-rails'

And then execute:

$ bundle

Or install it yourself (from rubygems) as:

$ gem install ember-konacha-rails

To see if the generators are installed:

$ rails g

Note: or use $ bundle exec rails g (to execute in context of current bundled environment)

...

EmberKonacha:
  ember_konacha:controller_spec
  ember_konacha:helper_spec
  ember_konacha:install
  ember_konacha:model_spec
  ember_konacha:view_spec

...  

Usage

Install basic Konacha infrastructure

$ rails g ember_konacha:install

Files that should be generated

vendor/assets/javascripts/sinon.js

spec/javascripts/spec_helper.js.coffee
spec/javascripts/support/sinon_mvc_mocks.js.coffee
spec/javascripts/support/koncha_config.js.coffee

spec/javascripts/app/router_spec.js.coffee
spec/javascripts/app/store_spec.js.coffee

Run examples

Clean run (default settings)

$ rails g ember_konacha:install gemfile konacha gemfile poltergeist create spec/javascripts/spec_helper.js.coffee create spec/javascripts/support/konacha_config.js.coffee create spec/javascripts/support/sinon_mvc_mocks.js Trying to download sinon.js (http://sinonjs.org/releases/sinon-1.6.js) ...
vendor assets/javascripts/sinon.js create spec/javascripts/app/store_spec.js.coffee create spec/javascripts/app/router_spec.js.coffee gsub app/assets/javascripts/application.js.coffee append app/assets/javascripts/application.js.coffee

Note: poltergeist requires you have installed PhantomJS headless JS driver.

via Homebrew:

brew install phantomjs

MacPorts:

sudo port install phantomjs

See https://github.com/jonleighton/poltergeist

Install generator was run previously

$ rails g ember_konacha:install
   identical  spec/javascripts/spec_helper.js.coffee
   identical  spec/javascripts/support/konacha_config.js.coffee
   identical  spec/javascripts/support/sinon_mvc_mocks.js
   identical  spec/javascripts/app/store_spec.js.coffee
   identical  spec/javascripts/app/router_spec.js.coffee
        gsub  app/assets/javascripts/application.js.coffee
      append  app/assets/javascripts/application.js.coffee

Now run Konacha!

$ bundle exec rake konacha:run

To run specs in browser

$ bundle exec rake konacha:serve
$ open http://localhost:3500

See more run options at https://github.com/jfirebaugh/konacha

Notice

Make sure that the following is at the end of your application.js.coffee file (or similar for pure javascript):

window.App = Ember.Application.create LOG_TRANSITIONS: true

# Defer App readiness until it should be advanced for either
# testing or production.
App.deferReadiness()

The basic test setup/configuration can be found in support/koncha_config.js.coffee and spec_helper.js.coffee files.

The spec_helper initializes the app explicitly using App.advanceReadiness() within Ember.run in the beforeEach closure. To run your app in the browser, while also allowing for testing, you need to explicitly call App.advanceReadiness(), f.ex when your DOM is ready.

$ ->
  App.advanceReadiness()

If you run the install generator with the --with-index option on, it will attempt to generate a standard application layout and index view file, with this all setup for you (using slim templating language!)

Install options

To see install options, run:

$ rails g ember_konacha:install --help

Note: To avoid having to bundle exec install the gem in your current system gem repository, use gem install ember_konacha (when this is an official gem!).

Guard Koncha config generator

To setup your project with Guard and execute koncha specs whenever your javascript assets change (default driver: poltergeist)

$ rails g ember_konacha:guard

To specify a specific js driver (selenium or webkit):

$ rails g ember_konacha:guard --driver wekbkit

Generate Controller spec

Use the --type or -t option to specify type of controller (will try to auto-determine otherwise)

$ rails g ember_konacha:controller_spec login -t base

spec/javascripts/controllers/login_controller_spec.js.coffee

$ rails g ember_konacha:controller User --type object

spec/javascripts/controllers/user_controller_spec.js.coffee

$ rails g ember_konacha:controller_spec Users -t array

spec/javascripts/controllers/user_controller_spec.js.coffee

$ rails g ember_konacha:controller_spec Users

Will autodetect that users is a plural form of user and assume you have an array (resource) controller.

$ rails g ember_konacha:helper_spec persons 

Will generate an object controller, since persons is not a valid plural form!

Generate Model spec

$ rails g ember_konacha:model_spec user

spec/javascripts/models/user_spec.js.coffee

Generate View spec

$ bundle exec rails g ember_konacha:view_spec NewUser

spec/javascripts/views/new_user_view_spec.js.coffee

Generate Helper spec

$ rails g ember_konacha:model_spec gravitation

spec/javascripts/helpers/gravitation_helper_spec.js.coffee

Sinon notice

The install generator will attempt to download sinon.js, first via httparty and then try via curl. On any exception it will fall back to just copying sinon-1.6.0.js.

Read more on [http://sinonjs.org/] for mocking, stubbing and creating test spies ;)

Application structure

A proposed Ember App structure is included for reference.

Contributing

Please help make it easier for developers tp get started using Test Driven Development (or BDD) for Ember with Rails.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Notes

Sample JSON REST controller (User resource)

class UsersController < APIController
  def index
    render_json users
  end

  def show
    render_json user
  end

  def destroy    
    render_json user.destroy
  end

  def update        
    render_json user.update(user_params)
  end

  def create    
    render_json user.save
  end

  protected

  def render_json data, opts = {}
    render json: data, opts
  end

  def new_user
    @new_user ||= User.new user_params
  end

  def users
    User.all.to_a
  end

  def user
    @user ||= User.find user_id
  end

  def user_id
    params[:id]
  end

  def user_params
    params[:user]
  end  
end

ember-konacha-rails's People

Contributors

kristianmandrup avatar

Watchers

Johnny Shields avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.