Giter Club home page Giter Club logo

teaspoon's Introduction

Teaspoon

Gem Version Build Status Maintainability Test Coverage License Reviewed by Hound

Logo by Morgan Keys

Logo by [Morgan Keys](https://twitter.com/morganrkeys)

Teaspoon is a Javascript test runner built for Rails. It can run tests in the browser and headless using PhantomJS, or Selenium WebDriver. It can also run your tests on selenium-webgrid providers such as BrowserStack.

The goal of Teaspoon is to be simple to use while also providing the most complete Javascript testing solution for Rails.

Teaspoon takes advantage of the Rails asset pipeline, and ships with support for Jasmine, Mocha, and QUnit.

If you'd like to use Teaspoon with Guard, check out the guard-teaspoon project. Or, if you want to use the Spring preloader, try the unofficial spring-commands-teaspoon.

Screenshots

Running in the console

Console Reporter

Running in the console using Tapout

Console Reporter Tapout

Running in the browser

Browser Reporter

Table of Contents

  1. Installation
  2. Usage
  3. Writing Specs
  4. Fixtures
  5. Suites
  6. Coverage
  7. Configuration
  8. Test Frameworks
  9. Support Libraries
  10. CI Support
  11. With BrowserStack

Installation

Add the framework-specific Teaspoon gem to your Gemfile. In most cases you'll want to restrict it to the :development, :test groups. The available gems are teaspoon-jasmine, teaspoon-mocha and teaspoon-qunit. If you're unsure which framework you'd like to use, we think Jasmine is a good starting place.

group :development, :test do
  gem "teaspoon-jasmine"
end

Run the install generator to get the environment file and a basic spec helper. If you want a CoffeeScript spec helper, you can tell the generator. Run the install generator with the --help flag for a list of available options.

rails generate teaspoon:install --coffee

To run Teaspoon headless you'll need PhantomJS or Selenium Webdriver.

Usage

Teaspoon uses the Rails asset pipeline to serve files. This allows you to use = require in your test files, and allows you use things like HAML or RABL/JBuilder within your fixtures.

Here's a great Quick Start Walkthrough for writing and running your first tests.

You can run Teaspoon three ways -- in the browser, via the rake task, and using the command line interface (CLI).

Browser

http://localhost:3000/teaspoon

Rake

rake teaspoon

The rake task provides several ways of focusing tests. You can specify the suite to run, the files to run, directories to run, etc.

rake teaspoon suite=my_fantastic_suite
rake teaspoon files=spec/javascripts/integration,spec/javascripts/calculator_spec.js
rake teaspoon driver_options="—ssl-protocol=TLSv1 --ignore-ssl-errors=yes"

CLI

bundle exec teaspoon

The CLI also provides several ways of focusing tests and is more full featured than the rake task. You can specify the suite to run, the files to run, directories to run, filters, etc.

bundle exec teaspoon --suite=my_fantastic_suite
bundle exec teaspoon spec/javascripts/integration spec/javascripts/calculator_spec.js
bundle exec teaspoon --filter="Calculator should add two digits"

Get full command line help:

bundle exec teaspoon --help

Note: The rake task and CLI run within the development environment for optimization unless otherwise specified.

Writing Specs

Depending on which framework you use this can differ, and there's an expectation that you have a certain level of familiarity with your chosen test framework.

Teaspoon supports Jasmine, Mocha and QUnit. And since it's possible to use the asset pipeline, feel free to use the = require directive throughout your specs and spec helpers.

Here's a basic spec written in Javascript using Jasmine:

//= require jquery
describe("My great feature", function() {

  it("will change the world", function() {
    expect(true).toBe(true);
    expect(jQuery).toBeDefined();
  });

});

You can also check out the examples of a Mocha Spec, and a QUnit Test.

Pending Specs

Every test framework is different, but we've tried to normalize some of those differences. For instance, Jasmine lacks the concept pending, while Mocha provides several ways to achieve this. So we thought it would be worth defining what is standard between the two frameworks. QUnit doesn't easily support the concept of pending, so that's not covered.

To mark a spec as pending in both Mocha and Jasmine, you can either not provide a function as the second argument to the it call, or you can use xit and xdescribe.

describe("My great feature", function() {
  it("hasn't been tested yet");

  xit("has a test I can't figure out", function() {
    expect("complexity").to.be("easily testable");
  });

  xdescribe("A whole section that I've not gotten to", function() {
    it("hasn't been tested yet", function() {
      expect(true).to.be(false);
    });
  });
});

Deferring Execution

Teaspoon allows deferring execution, which can be useful for asynchronous execution.

Teaspoon.defer = true;
setTimeout(Teaspoon.execute, 1000); // defers execution for 1 second

Using Require.js

There's a wiki article that goes into more depth on using RequireJS with Teaspoon. But in simple terms you can configure your suite to boot with RequireJS by setting the suite boot_partial directive to "boot_require_js".

Be sure to require require.js in your spec helper. Teaspoon doesn't include it as a support library, so you'll need to provide your own.

//= require require

Now require.js will be used to load all the specs in your suite, however, you'll still need to use require.js to pull down the dependencies as you would normally.

define(['Model'], function (Model) {
  describe('Model', function () {
    // ...
  });
});

Fixtures

Teaspoon ships with a fixture library that works with Jasmine, Mocha, and QUnit with minimal effort. It has a consistent API, and isn't dependent on jQuery.

The fixture path is configurable within Teaspoon, and the views will be rendered by a standard controller. This allows you to use things like RABL/JBuilder if you're building JSON, or HAML if you're building markup.

Loading Files

Loading fixtures allows you to specify any number of files to load, and if they should be appended to the fixture element or replace what's currently there.

fixture.load(url[, url, ...], append = false) or fixture(url[, url, ...], append = false)

Setting Manually

If you don't want to load files directly from the server you can provide strings instead of files, otherwise behaves like load.

fixture.set(html[, html, ...], append = false)

Cleaning Up

You shouldn't have to cleanup (we do that for you based on your test framework), but if you need it.

fixture.cleanup()

Preloading Files

Some test cases require stubbing Ajax requests, and in those cases you may want to preload the fixture files to cache them for later. You can preload fixtures in your spec helper, or before you start mocking Ajax methods.

fixture.preload(url[, url, ...])

Example Usage

fixture.preload("fixture.html", "fixture.json"); // make the actual requests for the files
describe("Using fixtures", function() {
  fixture.set("<h2>Another Title</h2>"); // create some markup manually (will be in a beforeEach)

  beforeEach(function() {
    this.fixtures = fixture.load("fixture.html", "fixture.json", true); // append these fixtures which were already cached
  });

  it("loads fixtures", function() {
    expect($("h1", fixture.el).text()).toBe("Title") // using fixture.el as a jquery scope
    expect($("h2", fixture.el).text()).toBe("Another Title")
    expect(this.fixtures[0]).toBe(fixture.el) // the element is available as a return value and through fixture.el
    expect(this.fixtures[1]).toEqual(fixture.json[0]) // the json for json fixtures is returned, and available in fixture.json
  });
});

Check out some example of using fixtures with Mocha, QUnit.

Note: The element that Teaspoon creates is "#teaspoon-fixtures", in case you need to access it directly and put your own fixtures in manually.

Suites

Teaspoon uses the concept of suites to group tests at a high level. These suites run in isolation and can have different configurations.

A default suite has been generated for you in your teaspoon_env.rb.

Suites inherit from a "default" suite. To modify this default, simply don't specify a name for the suite. In this example we're configuring the default, which all other suites will inherit from.

config.suite do |suite|
  suite.helper = "other_spec_helper.js"
end

When defining a custom suite, provide a name and a block. The following example defines a suite named "my_suite".

config.suite :my_suite do |suite|
  suite.helper = "my_spec_helper.js"
end

When defining multiple suites and running the tests on a CI (like Jenkins), you might need the output of bundle exec teaspoon in your XML-reports. To get one XML-file per suite you are running, you might want to add e.g a junit formatter which creates one result file per suite.

config.formatters = ["junit>#{Rails.root.join(["spec", "reports", "teaspoon_%{suite_name}.xml"])}"]

Will create a single file for each defined test-suite under spec/reports/teasoon_%{suite_name}.xml. Allowed placeholders are:

  • suite_name: the name defined by your config (config.suite :my_suite ...)
  • date: the execution timestamp of your test (Date.now.to_i)

Hooks

Hooks are designed to facilitate loading fixtures or other things that might be required on the back end before, after, or during running a suite or test.

You can define hooks in your suite configuration by specifying a name and a block. Hooks with the same name will be added to an array, and all configured hook callbacks with that name will be called when the hook is requested. If you don't specify a name, :default will be assumed.

config.suite :my_suite do |suite|
  suite.hook :fixtures do
    # some code that would load your fixtures
  end

  suite.hook :setup do |arguments|
    # some code that has access to your passed in arguments
  end
end

Once hooks have been defined in your configuration, you can invoke them using the javascript Teaspoon.hook interface in your specs. A request will be sent to the server, where all blocks that have been specified for a given hook will be called in the order they were defined. Any arguments passed to Teaspoon.hook will be provided to the hooks defined in the configuration.

Teaspoon.hook('fixtures')
Teaspoon.hook('setup', {foo: 'bar'})

Coverage

Teaspoon uses Istanbul to generate code coverage statistics and reports. You can define coverage configurations the same way you define suites.

Note: Ensure that you are using Istanbul version v0.3.0 or greater.

Each suite allows specifying ignored files, which allows you to ignore support libraries and dependencies.

The following configuration and example generates a text and cobertura report -- and an annotated HTML report that you can inspect further.

config.coverage do |coverage|
  coverage.reports = ['text', 'html', 'cobertura']
end
bundle exec teaspoon --coverage=default

If you use the "text", or "text-summary" reports, they will be output to the console after the tests have completed.

--------------------+-----------+-----------+-----------+-----------+
File                |   % Stmts |% Branches |   % Funcs |   % Lines |
--------------------+-----------+-----------+-----------+-----------+
  phantomjs/        |     93.75 |        75 |     94.12 |     93.65 |
    runner.js       |     93.75 |        75 |     94.12 |     93.65 |
--------------------+-----------+-----------+-----------+-----------+
All files           |     93.75 |        75 |     94.12 |     93.65 |
--------------------+-----------+-----------+-----------+-----------+

Caveats

In order to provide accurate coverage and best performance, it is recommended that you require the implementation file directly from the spec file. For example:

//= require "my_class"
describe("MyClass", function() { ... });

It is not recommended that you require the entirety of your assets from within your spec helper:

spec_helper.js

//= require "application"

If you must require application from your spec helper and you have expand_assets configuration set to false, you'll need to exclude the spec helper from ignored coverage files:

teaspoon_env.rb

config.coverage do |coverage|
  coverage.ignore = coverage.ignore.reject { |matcher| matcher.match('/spec_helper.') }
end

Thresholds

Teaspoon allows defining coverage threshold requirements. If a threshold is not met, it will cause a test run failure.

This example would cause a failure if less than 50% of the statements were not covered by the tests for instance.

config.coverage :CI do |coverage|
  coverage.statements = 50
  coverage.functions  = 50
  coverage.branches   = 50
  coverage.lines      = 50
end

Configuration

When you install Teaspoon a teaspoon_env.rb file is generated that contains good documentation for each configuration directive. Otherwise you can get a refresher by checking the Teaspoon Configuration article.

Note If you want teaspoon_env.rb to live in a location other than the default install path, you can specify an alternate path in a TEASPOON_ENV environment variable (eg $ TEASPOON_ENV=config/teaspoon.rb teaspoon).

Test Frameworks

Jasmine is one of the first BDD-style frameworks. We've been using Jasmine for a long time, and have been pretty happy with it. It lacks a few important things that could be in a test framework, so we've done a little bit of work to make that nicer. Like adding pending spec support.

Mocha came up while we were working on Teaspoon -- we read up about it and thought it was a pretty awesome library with some really great approaches to some of the things that some of us browser types should consider more often, so we included it and added support for it. We encourage you to give it a try. Read more about Using Mocha with Teaspoon.

QUnit We're not sure about how many people use QUnit, but we like jQuery, so we added it. Read more about Using QUnit with Teaspoon.

If you'd like to see what frameworks and versions Teaspoon supports, you can run rake teaspoon:info. The results of this will be restricted by what framework gems you have included in your Gemfile.

Support Libraries

We know that testing usually requires more than just the test framework, so we've included some of the libraries that we use on a regular basis.

  • Sinon.JS (1.8.2) Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework. BSD Licence.
  • ChaiJS (1.8.1) BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework. MIT License.
  • Chai-jQ (0.0.7) An alternate plugin for the Chai assertion library to provide jQuery-specific assertions. MIT License.
  • Sinon-Chai (1.0.0) Extends Chai with assertions for the Sinon.JS mocking framework. MIT-ish License.
  • expect.js (0.1.2) Minimalistic BDD assertion toolkit based on should.js. MIT License.
  • jasmine-jquery-1.7.0.js (1.7.0) For Jasmine v1, A set of custom matchers for jQuery, and an API for handling HTML fixtures in your specs. MIT License.
  • jasmine-jquery-2.0.0.js (2.0.0) For Jasmine v2, A set of custom matchers for jQuery, and an API for handling HTML fixtures in your specs. MIT License.

You can require the various support files in your spec helper by using:

//= require support/sinon
//= require support/chai
//= require support/chai-1.10.0
//= require support/sinon-chai
//= require support/expect
//= require support/jasmine-jquery-1.7.0
//= require support/jasmine-jquery-2.0.0

CI Support

Teaspoon works great on CI setups, and we've spent a good amount of time on getting that good. There's a lot of information to go over with that topic, but here are some highlights.

Add a line to execute Teaspoon (e.g. bundle exec teaspoon) in your CI config file. If you're using TravisCI or CircleCI it just works, but if you're using something else all you should need is to ensure PhantomJS is installed.

Alternately, you can add Teaspoon to the default rake tasks by clearing out the defaults (not always required), and then add :teaspoon into the chain of tasks where you want.

Rake::Task['default'].prerequisites.clear
Rake::Task['default'].clear

task default: [:spec, :teaspoon, :cucumber]

Some build services also support selenium based setups using Xvfb and Firefox. This works well on on TravisCI, and we've heard of some success doing this on CircleCI, however if you are experiencing timeouts try to add a post-dependency command to precompile your assets (eg. rake assets:precompile.

If you want to generate reports that CI can use you can install Istanbul for coverage reports -- and output the report using the cobertura format, which Hudson and some others can read. You can track spec failure rates by using the tap formatter, or on TeamCity setups you can use the teamcity formatter. A junit formatter is available as well.

We encourage you to experiment and let us know. Feel free to create a wiki article about what you did to get it working on your CI setup.

Running your javascript tests on the BrowserStack infrastructure is easy with the included browserstack driver.

In teaspoon_env.rb configure your driver to config.driver = :browserstack. You must add the browsers you'd like to test on as an array of hashes with key capabilities in config.driver_options. More details about the driver configurations are available on the Using BrowserStack WebDriver wiki article.

By default you can run 10 tests in parallel by default, and the number of tests running in parallel can be specified using the max_parallel driver option.

Now you can run Teaspoon locally and can see your tests running on the BrowserStack Automate Dashboard.

Alternative Projects

License

Licensed under the MIT License

Copyright 2016 jejacks0n

All licenses for the bundled Javascript libraries are included (MIT/BSD).

Make Code Not War

teaspoon's People

Contributors

baburdick avatar bouk avatar chrisnicola avatar garysweaver avatar iainbeeston avatar inlineblock avatar jabr avatar jejacks0n avatar kaanozkan avatar kowal avatar leppert avatar liseki avatar mathieujobin avatar mikepack avatar mortonfox avatar nilbus avatar pboling avatar rafaelfranca avatar rafalbromirski avatar rwjblue avatar sblackstone avatar sebastianzillessen avatar sguha00 avatar smellsblue avatar trbrink avatar trevmex avatar ukdave avatar virginia-rodriguez avatar ysbaddaden avatar zackmattor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

teaspoon's Issues

angular scenario support

How hard do you think it would be to have an adapter for angular scenario, so that we could have an E2E testing suite in teabag?

Markup not escaped in browser

When running tests in the browser, "<" and ">" (at least) should be escaped.

I have some Jasmine tests like the following:

it("generates a <div> tag", function() { /* Test code */ });

and that will be rendered in the browser without escaping the tag, so I end up with a unclosed div with the word "tag" inside it.

Is Railtie really a dependency

I really appreciate this gem, but lately I've been working with Sinatra more than Rails.

Keeping this is mind my sugestion is remove the Railtie dependency and rely only on Rack to mount the application. This will continue to support rails apps and will allow any other rack based apps to work with the gem.

If you are interested in this approach I could clone the repo and do the basics, but I will need support to understand the complete flow. What you guys think?

Consider renaming the project?

Have you considered renaming the project? When my intern googled for this project he was lead to the urban dictionary definition. He's very young and innocent...

Rake task does not abort when PhantomJS fails

Hi,
I've a build server when running the teabag rake task it logs:

Starting the Teabag server...
Teabag running default suite at http://127.0.0.1:36846/teabag/default
[myprojectpath]/vendor/bundle/ruby/1.9.1/gems/phantomjs-linux-0.0.2/lib/../vendor/phantomjs/linux/bin/phantomjs: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

and continues with its other tasks. I expected teabag to abort rake like when a test fails.

(any clues on what went wrong are welcome as well)

I'm running this on a CentOS 6.4 64-bit machine. I did not have this issue with Ubuntu 12.04 64bit.

Teabag and requirejs...how to set it up?

I know from the wiki page that there is support for AMD, but how do you set it up to make it work

when I run teabag spec/javascripts/models/location_spec.js I get: 0 examples, 0 failures

//=require require
//=require config
define(['models/Location'], function(Location) {

  return describe('Model :: Location', function() {

    describe('Model properties', function() {

      it('should have a name', function() {
        var name_value = "San Fransisco";
        var locationModel = new Location({
          name: name_value
        });
        expect(locationModel.get("name")).toEqual(name_value);
      });
    });
  });
});

in this specific example, where do I need to put the defer option?

Teabag.defer = true
setTimeout(Teabag.execute, 1000) // defers execution for 1 second

application.js.coffee not loading

Hiya,

When running rake teabag or going to localhost:3000/teabag, it doesn't seem to be picking up any files that I have listed in my application.js (or application.js.coffee) file, strangely. My application works fine, so I know the Rails asset pipeline is working, but teabag doesn't seem to be using it?

Any insights would be helpful. Thanks!

NoMethodError with "suite.use_require = true" for require.js

Steps to reproduce:

rvm gemset create test1
rvm gemset use test1

gem list

  • bundler (1.3.5)
  • rake (10.0.4)
  • rubygems-bundler (1.1.1)
  • rvm (1.11.3.7)

gem install rails

  • Ruby: 1.9.3p429
  • Rails: 3.2.13

rails new test1

Added to Gemfile:

gem "requirejs-rails", "~> 0.9.1"
gem "jasmine", "~> 1.3.2"
gem "teabag", "~> 0.7.2"

bundle install

rails generate jasmine:install
rails generate teabag:install --coffee
rails generate controller home index

Added to config/routes.rb

  root to: 'home#index'

Removed public/index.html

I followed these instructions to set up an initial test.

Added spec/javascripts/calculator_spec.coffee

#= require calculator
describe "Calculator", ->
  it "should add two digits", ->
    expect( new Calculator().add(2,2) ).toBe(4)

Added app/assets/javascripts/calculator.coffee

class @Calculator
  add: (a, b) ->
    a + b

Running teabag results in 1 example passing, 0 failures.

So far success. Want to try a require.js workflow.

Changed app/views/layouts/application.html.erb (and removed javascript_include_tag)

  <%= requirejs_include_tag 'application' %>

Added to spec/javascripts/spec_helper.coffee (and removed #= require application)

#= require require

Changed app/assets/javascripts/calculator.coffee

define ->
  add: (a, b) ->
    a + b

Changed app/assets/javascripts/application.coffee

define ['jquery', 'calculator'], ($, calc) ->
  $ ->
    alert calc.add(4,5)

Running rails server and loading it in a web browser I see the alert with the results from the script loaded by Require.js. According to Webkit Inspector, require.js, jquery.js, and calculator.js are all loaded.

How do I switch the calculator_spec.coffee file to use require.js?

If I change it to:

define ['calculator'], (calc) ->
  describe 'Calculator', ->
    it 'should add two digits', ->
      expect(new calc.add(2,3)).toBe(5)

…when I run teabag it now says 0 examples, 0 failures. According to the README, I should put suite.use_require = true in config/initializers/teabag.rb in the appropriate block, but it results in a NoMethodError:

Error: NoMethodError: undefined method `use_require=' for #Teabag::Configuration::Suite:0x007…

On RequireJS with Teabag it mentions a require.config block, but adding it to spec_helper.coffee still results with 0 examples. I've tried various incarnations of config/requirejs.yml as per requirejs-rails but still 0 examples.

Any help?

Tests restarting

We have some tests written for Backbone.js routers that check hash changes. It appears that teabag watches the hashchange event and does its own things, restarting the tests part way. We get into a loop of tests restarting. Any help?

EDIT: Ok, more looking appears not to be a hash problem, more like a problem when rendering views... I will keep this updated if I find more.

Gem includes unnecessary generated files

I noticed that this gem was unusually large, so I investigated and it looks like some generated test data is being included in the packaged version that is not checked into git.

Freshly checked out from git:

$ du -sh teabag/
5.3M    teabag/

Unpacked gem version:

$ du -sh teabag-0.7.2/
51M teabag-0.7.2/
$ du -sh teabag-0.7.2/spec/dummy/*
44K teabag-0.7.2/spec/dummy/app
40K teabag-0.7.2/spec/dummy/config
4.0K    teabag-0.7.2/spec/dummy/config.ru
34M teabag-0.7.2/spec/dummy/log
4.0K    teabag-0.7.2/spec/dummy/public
4.0K    teabag-0.7.2/spec/dummy/Rakefile
8.0K    teabag-0.7.2/spec/dummy/script
14M teabag-0.7.2/spec/dummy/tmp

I'm not too familiar with building gems, but I think this could be fixed by simply removing this line from the gemspec: https://github.com/modeset/teabag/blob/master/teabag.gemspec#L17
The packaged gem does not include a Gemfile or Rakefile, so the tests don't really seem to serve a purpose anyways.

Ensure that the HTML reporter is working in IE6+

To allow the broadest testing ability we should ensure that the HTML reporter is in fact working (and looks tolerable) in IE6.

We're doing everything pretty old school style, but nobody has checked this yet.

If anyone is willing to fire up a VM and check that would be awesome too.

Weird error was my fault

I had a problem loading my coffeescripts from my specs, and I was using a sublime plugin that was generating coffeescripts to javascripts - and it was replacing my spec_helper.js file and it was basically erasing my require imports in rails - which coffeescript generators delete.

If anybody else runs into that problem be careful with this coffescript sublime generator.

Not enough error details

My spec pass when they are run in a browser but they fail on console with rake teabag and phantomjs.

I'm trying to debug the issue...but the trace isn't very helpful...

  1) Foo submits form when uploading
     Failure/Error: ReferenceError: Can't find variable: page

That's basically all I get...no file and line number.
Any tips on getting better traces? Or is this a limitation of teabag/phantomjs?

Support using already running server

It doesn't seem to be possible to use an already running server (like localhost:3000). If it is, I don't see it documented. Is this possible now? If not, it would be great for command line use so I didn't have to start a rails server every time. Thanks!

undefined cattr_accessor when attempting to run using cli.

This is just after doing a clean install of teabag.

/home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/configuration.rb:7:in `<class:Configuration>': undefined method `cattr_accessor' for Teabag::Configuration:Class (NoMethodError)
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/configuration.rb:4:in `<module:Teabag>'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/configuration.rb:3:in `<top (required)>'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag.rb:3:in `require'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag.rb:3:in `<top (required)>'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/environment.rb:12:in `require'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/environment.rb:12:in `load' 
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/console.rb:12:in `initialize'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/command_line.rb:13:in `new'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/lib/teabag/command_line.rb:13:in `initialize'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/bin/teabag:6:in `new'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/gems/teabag-0.7.1/bin/teabag:6:in `<top (required)>'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/bin/teabag:19:in `load' 
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/bin/teabag:19:in `<main>'
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/bin/ruby_noexec_wrapper:14:in `eval' 
  from /home/paul/.rvm/gems/ruby-1.9.3-p374@blah/bin/ruby_noexec_wrapper:14:in `<main>'

PhantomJS Error Message

Teabag is running specs from the command line - yea! But I get a funky error message "No such file or directory..."

Starting the Teabag server... 
Teabag running default suite at http://127.0.0.1:42806/teabag/default
./bin/rake: No such file or directory - phantomjs --version
./bin/rake: No such file or directory - phantomjs --version
.
Finished in 0.00500 seconds
1 example, 0 failures

Any ideas re: how to suppress/eliminate this message?

I'm running: Ubuntu 12.04 32-bit, teabag 0.7.1, ruby 1.9.3p327perf, rails 3.2.13.

I tried:

  • gem 'phantomjs-linux' #=> made no difference
  • apt-get install phantomjs #=> broke teabag, even when setting PHANTOMJS_BIN

Running specific files on command line

I'm trying to run bundle exec teabag for many files, 28 files to be exact...so my command looks something like this:

$ bundle exec teabag spec/javascripts/file1_spec.coffee spec/javascripts/file2_spec.coffee spec/javascripts/file3_spec.coffee ... spec/javascripts/file28_spec.coffee

However, teabag fails to load:

Error: Failed to load: http://127.0.0.1:52126/teabag/default/?file[]=spec/javascripts/file1_spec.coffee&file[]=spec/javascripts/file2_spec.coffee.....

My guess is that this is because the URL is too long. If that is the case, would you be better off POSTing to the teabag server instead of doing a GET? Or is there a better way to run a (potentially long) list of files through the command line?

Provide better error messaging when test runner fails to run.

There are all sorts of reasons that can cause the test runner to fail.. if you require a file that doesn't exist, or you have a coffeescript parse error etc.

We should handle these cases better and display an error message in the console about what happened.

"passes: 0 failures: 0 skipped: 0 duration: ∞" with redundant require?

Hi,

Loving Teabag.

In the course of trying to get an existing test to run, I put

#= require jasmine

at the top of my test file. This causes the test to report

passes: 0 failures: 0 skipped: 0 duration: ∞

There were no errors reported on the FireFox console, nor from the rails server.

(My actual problem was that I was missing '#= require jasmine-jquery' -- I just hadn't figured that out.)

Anyway, this will cause your calculator_spec to get the same non-result.

Sharing for the benefit of those who might make the same stupid mistake as me, and to help you tune up your excellent project to withstand stupid errors! :)

No CoffeeScript support for QUnit?

I'd rather use Jasmine, but I'm stuck with QUnit.

I've got teabag up and running (I can run example tests), but for some reason I can't run coffeescript specs. I've put the exact same test in as .js and it passes.

All of my setup is direct from the generator:

rails generate teabag:install --framework=qunit --coffee

I can paste in any other files you need!! I appreciate your time!

Improve the user interface in the HTML reporter by adding a select for switching suites.

It's annoying to have to know their names and type them into the url. There can be a select or list or something that allows a user to select which suite they want to run from within the interface itself.

Another potential adjustment to keep users from having to fudge with the url string is to provide a filter input that works much like the grep query param.

Catchall routes make teabag inaccessible

Just as an fyi, if you have a catchall route at the bottom of your routes file in Rails, it makes Teabag inaccessible.

match '*path' => 'errors#missing'

You can get around this by manually mounting the Teabag::Engine in your routes.

Suite OK in browser, NOK in shell

Hi,

I have a suite of specs ran using teaspoon-mocha and chai which is running fine in the browser, but fails when ran in the console:

$ bundle exec rake teaspoon suite=default
Starting the Teaspoon server...
I, [2013-06-24T10:29:52.267705 #30128]  INFO -- : listening on addr=0.0.0.0:48599 fd=9
I, [2013-06-24T10:29:52.267838 #30128]  INFO -- : worker=0 spawning...
I, [2013-06-24T10:29:52.269526 #30168]  INFO -- : worker=0 spawned pid=30168
I, [2013-06-24T10:29:52.269694 #30128]  INFO -- : master process ready
I, [2013-06-24T10:29:52.272254 #30168]  INFO -- : worker=0 ready
Teaspoon running default suite at http://127.0.0.1:48599/specs/default
Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 8: reading configurations from ~/.fonts.conf.d is deprecated.
TypeError: 'undefined' is not an object (evaluating 'this.suite.parent.root')
  # teaspoon-mocha.js:6624 -- Suite
  # teaspoon-mocha.js:6591
  # teaspoon-mocha.js:6348
  # teaspoon-mocha.js:6373
  # teaspoon-mocha.js:6471
  # teaspoon-mocha.js:6448
  # teaspoon-mocha.js:521
  # teaspoon-mocha.js:4481
  # teaspoon-mocha.js:4432
  # teaspoon-mocha.js:4489
  # teaspoon-mocha.js:4356 -- next
  # teaspoon-mocha.js:4365
  # teaspoon-mocha.js:4313 -- next
  # teaspoon-mocha.js:4333
  # teaspoon-mocha.js:5315 -- timeslice

The error occurs in the prototype definition of Teaspoon.Suite.

This specs suite was once ran under Konacha, so all the specs are part of a "Default" suite, but there are no explicit declaration concerning the notion of a suite whatsoever. Should we organize our tests in explicit suites?

Thank you.

error in html runner

getting an uncaught exception
Uncaught TypeError: Cannot set property 'innerHTML' of null

BaseView.prototype.setHtml = function(id, value, add) {
  var el;
  if (add == null) {
    add = false;
  }
  el = this.findEl(id);
  if (add) {
    return el.innerHTML += value;
  } else {
    return el.innerHTML = value;
  Uncaught TypeError: Cannot set property 'innerHTML' of null
  }
};

Making backtrace urls clickable?

Are you guys using anything to make backtrace url's clickable? In other words when using the browser runner my failing specs provide me backtraces that look like: http://localhost:3000/path/to/my/sepc.js?body=1:9:25. These seems ripe for clicking and focusing.

Any browser extensions in your workflow?

Fix up angular test support

Since I'm not using Angular directly this will require a good amount of research, but I've been intending to check it out and learn something. This is a placeholder to communicate that I don't believe Angular support is what it should be and needs work.

howto?: testing ready events with fixtures

Hi,

I recently decided my javascript code should be tested as well and now looking into testing with jasmine using teabag.
I noticed that a lot of my javascript code (the little i have) is code like: at document.ready, decorate some html-element.

So here's what I did: I made a fixture containing the element i needed to decorate. However, my fixtures get loaded after ready was triggered, so the fixture does not get decorated.

The easy fix would be of course to refactor all that is done in the event handler into a new function and then test the new function, but that feels a bit hacky.

I would like to know whether you have some suggestions on how to do this easier/better/neater?

passes: 0 failures: 0 skipped: 0 duration: ∞

(Note: I originally submitted this under teabag-demo, but decided it may reflect a problem in teabag itself, so am submitting it here as well.)

I am very keen to use teabag -- exactly what I need for testing my rails with JavaScript, from the looks of it!

However, I can't get even the simplest test to work. Thinking I must have some incompatibility with my version of Ruby or some gem, I tried cloning the teabag demo, built it, ran the rails server, and navigated to http://localhost:3000/teabag. What it shows is "passes: 0 failures: 0 skipped: 0 duration: ∞". As best I know how, teabag-demo is using the exact versions of Ruby and all gems as specified by the .rvmrc and Gemfile/Gemfile.lock.

No errors are shown from the rails server, but using Firefox, I looked at the console and see the error

TypeError: this.findEl(...) is null
[Break On This Error]   

this.findEl("suite-select").onchange = this.changeSuite;

teabag...?body=1 (line 2815)

Ruby is 1.9.3p392:

ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]

I'll include my Gemfile and Gemfile.lock here too in case that helps:

Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


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

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
  gem "teabag"
end

gem 'phantomjs-linux'


gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.9)
      actionpack (= 3.2.9)
      mail (~> 2.4.4)
    actionpack (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.2.1)
    activemodel (3.2.9)
      activesupport (= 3.2.9)
      builder (~> 3.0.0)
    activerecord (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
    activesupport (3.2.9)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.4)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.4.0)
    erubis (2.7.0)
    execjs (1.4.0)
      multi_json (~> 1.0)
    hike (1.2.1)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (2.1.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.7.5)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.19)
    multi_json (1.5.0)
    phantomjs-linux (0.0.2)
    phantomjs-mac (0.0.3)
    phantomjs.rb (0.0.5)
      phantomjs-mac
    polyglot (0.3.3)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.9)
      actionmailer (= 3.2.9)
      actionpack (= 3.2.9)
      activerecord (= 3.2.9)
      activeresource (= 3.2.9)
      activesupport (= 3.2.9)
      bundler (~> 1.0)
      railties (= 3.2.9)
    railties (3.2.9)
      actionpack (= 3.2.9)
      activesupport (= 3.2.9)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (10.0.3)
    rdoc (3.12)
      json (~> 1.4)
    sass (3.2.4)
    sass-rails (3.2.5)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    sprockets (2.2.2)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.6)
    teabag (0.4.1)
      phantomjs.rb (~> 0.0.5)
      railties (~> 3.2.5)
    thor (0.16.0)
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.35)
    uglifier (1.3.0)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)

PLATFORMS
  ruby

DEPENDENCIES
  coffee-rails (~> 3.2.1)
  jquery-rails
  phantomjs-linux
  rails (= 3.2.9)
  sass-rails (~> 3.2.3)
  sqlite3
  teabag
  uglifier (>= 1.0.3)

Is my SpecController running slow?

The browser runner feels kinda slow. Visiting /teabag completes in < 100ms - which is fine, but, visiting /teabag/default/?file=... it takes > 2 seconds.

Is this typical? Is something wrong with my setup?

The spec I'm running is a single expect(true).to.be(true) assertion. The development log says all the time is spent on the view rendering of Teabag::SpecController#runner.

Object #<Assertion> has no method 'throw'

Hi,

Using teaspoon and

#= require support/chai
#= require support/expect

I end up having weird errors such as Object #<Assertion> has no method 'throw' coming from an expect(fn).to.throw Error (which passes under Konacha, for instance). Some other chai helpers are "missing" as well, such as instanceof. The majority of them are present, though… so it's kind of weird.

I'm feeling this could be more a chai-related issue, but you may have encountered the issue already.

Using externally hosted javascript

I'm trying to test some code that relies on the google maps api. Unfortunately there doesn't seem to be any way of mocking that or hosting it locally, and other projects (eg. hpneo/gmaps) test it by including a script tag for gmaps in their tests. But I can't find a way of doing this using teabag.

I've tried including script tags in my fixture, but they don't seem to be evaluated. Sprockets doesn't allow for remotely hosted dependencies. And so far as I can see from the source teabag only supports inclusion of dependencies via sprockets, and I can't access it's view templates.

I'm not entirely sure if this is a bug, because it's for a fairly questionable practice, but I suspect there is a subset of libraries that require this feature.

Add QUnit support.

I think this is do-able, so I'll probably add it if there's any demand for it. The only issues I see are the complication with the path -- spec vs. test.. but breaking some of the framework specific stuff into wiki pages would make the readme easier on the eyes too.

No such file or directory on running teabag

RAILS_ENV=test bundle exec rake teabag
Starting server...
Teabag running default suite at http://127.0.0.1:39270/teabag/default...
rake aborted!
No such file or directory - /home/paul/.rvm/gems/ruby-1.9.3-p194/gems/phantomjs-linux-0.0.2/lib/../vendor/phantomjs/linux/bin/phantomjs /home/paul/.rvm/gems/ruby-1.9.3-p194/gems/teabag-0.4.0/lib/teabag/drivers/phantomjs/runner.coffee http://127.0.0.1:39270/teabag/default

Both of those paths exist, so I'm unsure what the problem is. Using gem from github (v 0.0.5), also happens in development.

Selenium: Teabag::UnknownSuite

Hi there!

I'm using teabag with selenium driver. When I run rake teabag, the test suite won't run due to a Teabag::UnknownSuite error. I noticed that when Firefox shows up, the URL on the address bar is wrong. It says: http://127.0.0.1:50529/teabag/default&reporter=Console.

So I looked at the source code and found these lines of code.

It seems that if there are no specified filters, the ? won't be added to the URL. In that case, adding &reporter=Console will result to an unknown suite.

I think it'll be better to add a ? even if there are no filters. That way, adding the reporter string to the URL won't result to an error. I'm not familiar with the code base though. There might be a reason why the ? is not being added by default?

On Windows, coverage runs from the TEMP directory, obfuscating results

This results in file paths such as /d20130515-37084-102j7jj/my_javascript.js
What is the problem? Well each file is in a separate obfuscated directory.

I have tried searching for a solution, but google isn't very helpful since teabag and istanbul are so common. StackOverflow yielded no answers either.

Selenium and PhantomJS give the exact same result.

Add coverage threshold checking

I would like to use istanbul's check-coverage feature, but I think it requires the presence of the coverage.json file. It looks like teabag creates it in a temp directory, which is cleaned up after the coverage report is generated.

Would you accept a patch to copy this file into the coverage/ directory after the report is generated? I believe this should allow me to then run istanbul check-coverage <options> to do things like checking that thresholds were not exceeded.

Add better fixture support that will work across test frameworks.

We're using jasmine-jquery now, but feel we can provide a more standard interface for using fixtures.

Keeping the ability to use jasmine-jquery or sinon as they work currently.

The public interface for fixtures should be something like:

describe "Feature"

   # loading a fixture -- either pass format, or response headers can be used to determine if it should be JSON, HTML, etc.
   # HTML will be auto loaded into the fixture element.
   # JSON will just be parsed and available as an object?
   fixture("path/to/filename", "html")

   it "can find the fixture" ->
      # without arguments the fixture function should return the last fixture -- either the element, or json object?
      expect(fixture()).toBeDefined()

Those are my initial thoughts.

Project Name Change?

Quite a great looking project you have here. Just wondering if you have considered the potentially offensive name of the project however? Might end up with a repeat of the Testacular changed to Karma fiasco down the road as your project gains more attention.

Add fixtures.$el

I find myself throwing fixtures.el into $(fixtures.el) a lot....Would it make sense to add fixtures.$el, kinda like backbone?

Rake Teabag fails randomly

I have a fully passing test suite in the browser, but on rake teabag it gets a majority of the we through tests and stops with this message printed: "Error: Failed to load: http://127.0.0.1:50701/teabag/default/?"

I was working on tests and caused a fail then this happened. I reverted my changes to my code base and it never went away... it gets to different points in the tests when it fails too.

Any way to provide better feedback? And get tests passing? Could this be a cache thing?

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.