AngularJS e2e testing in Rails stack: [object Object] has no method 'resumeBootstrap' - ruby-on-rails

It seems quite hard to get the AngularJS/Karma end-to-end testing environment working with a Rails backend.
I have Karma installed and running with the following config file:
basePath = '../';
files = [
ANGULAR_SCENARIO,
ANGULAR_SCENARIO_ADAPTER,
'test/e2e/**/*.js'
];
autoWatch = false;
browsers = ['Chrome'];
// singleRun = true;
proxies = {
'/': 'http://local.mywebsite.com:3000/'
};
urlRoot = 'e2e';
junitReporter = {
outputFile: 'test_out/e2e.xml',
suite: 'e2e'
};
Where http://local.mywebsite.com:3000/ is my rails application.
I try a very simple test:
it('should redirect to /', function() {
expect(browser().location().url()).toBe("/");
});
But I am stuck with the following error:
http://localhost:9876/base/test/e2e/scenarios.js:8:5
TypeError: Object [object Object] has no method 'resumeBootstrap'
at HTMLIFrameElement.<anonymous> (http://localhost:9876/adapter/lib/angular-scenario.js:26285:27)
at HTMLIFrameElement.jQuery.event.dispatch (http://localhost:9876/adapter/lib/angular-scenario.js:3064:9)
at HTMLIFrameElement.elemData.handle.eventHandle (http://localhost:9876/adapter/lib/angular-scenario.js:2682:28)
at k (http://connect.facebook.net/en_US/all.js:48:745)
Where scenarios.js comes from https://github.com/angular/angular-seed.
Any idea how to make it work?

Try
it('should redirect to /', function() {
browser().navigateTo("/");
expect(browser().window().path()).toBe("/");
});

I would get the most up-to-date version of angular scenario runner. You can find the unstable version at
http://code.angularjs.org/1.1.4/angular-scenario.js
and the stable version at
http://code.angularjs.org/1.0.6/angular-scenario.js
Then, be sure to update your karma configuration to use the newest scenario runner
files = [
'path/to/angular-scenario.js',
ANGULAR_SCENARIO_ADAPTER,
'test/e2e/**/*.js'
];
Hopefully that helps.

The solution above is correct. This link covers the problem: https://github.com/karma-runner/karma/issues/470
I hit the same issue while running the excellent examples on: http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html
That's a great resource if you're getting started, but you will need to update from testacular to karma and update angularjs to 1.0.6

Related

Rails angular coffeescript error

I'm using angularjs-rails gem.
I've created angular_app folder in assets, and have angular_app/controllers/phoneListController.js.coffee, and angular_app/modules/phoneCatApp.js.coffee (*yeah you're right I'm doing angular's phone tutorial ). So angular_app/controllers/phoneListController.js.coffee has:
phonecatApp.controller 'PhoneListController', ($scope) ->
$scope.phones = [
{ 'name': 'Nexus S'
'snippet': 'Fast just got faster with Nexus S.'
}
{
'name': 'Motorola XOOMâ„¢ with Wi-Fi'
'snippet': 'The Next, Next Generation tablet.'
}
{
'name': 'MOTOROLA XOOMâ„¢'
'snippet': 'The Next, Next Generation tablet.'
}
]
return
angular_app/modules/phoneCatApp.js.coffee has:
phonecatApp = angular.module('phonecatApp', [])
Every thing works fine if I use vanila js in angular_app/modules/phoneCatApp.js.coffee using `phonecatApp = angular.module('phonecatApp', [])`` (with backsticks).
So problem is that coffee covers all in anonymous function with ().call.this. What should I do to make it work in coffee?
The problem, as you've stated, is the
(function() { ... }).call(this)
that the coffeescript compiler generates. To make phonecatApp a global simply do
this.phonecatApp = phonecatApp
in your angular_app/modules/phoneCatApp.js.coffee file after the angular.module() call.
However, MUCH better is to use:
angular.module('phonecatApp').controller( ... )
to define your controllers. This version gets angular to provide the module singleton on which to define the controller.

Konacha, Mocha, BackboneJS and Ruby on Rails configuration

I am using Konacha to test a BackboneJS application in my Ruby on Rails application. I have read about every tutorial on the web and it shows how easy it is to set up and get working. Unfortunately, I am not having this level of success. Here is what I have:
app/assets/javascripts/app_specific/itapp/models/post.js
Itapp.Models.Post = Backbone.Model.extend({
isFirstPost: function() {
return (this.get('id') === Itapp.bootstrap.posts[0].get('id'));
},
});
spec/javascripts/app_specific/itapp/models/post_spec.js
//= require spec_helper
var expect = chai.expect;
describe("Posts", function() {
it("should have a first post", function() {
//just trying anything to get some kind of valid error/issue
//I could put anything here and it wouldn't matter, just FYI
expect(typeof this.isFirstPost).to.equal('function');
});
});
spec/javascripts/spec_helper.js file:
// Require the appropriate asset-pipeline files:
//= require application
//Any other testing specific code here...
//Custom matchers, etc....
Konacha.mochaOptions.ignoreLeaks = true
beforeEach(function() {
return window.page = $("#konacha");
});
// set the Mocha test interface
// see http://mochajs.org/#interfaces
mocha.ui('bdd');
//
// ignore the following globals during leak detection
mocha.globals(['YUI']);
//
// or, ignore all leaks
mocha.ignoreLeaks();
//
// set slow test timeout in ms
mocha.timeout(5);
//
// Show stack trace on failing assertion.
chai.config.includeStack = true;
I do have a config/initializers/konacha.rb file:
Konacha.configure do |config|
config.spec_dir = "spec/javascripts"
config.spec_matcher = /_spec\.|_test\./
config.stylesheets = %w(application)
config.driver = :selenium
end if defined?(Konacha)
The error I am getting:
Error: Failed to load app_specific/itapp/collections/posts_spec.js.
Perhaps it failed to compile? Check the rake output for errors.
Checking the rake output:
ActionView::Template::Error: couldn't find file 'application' which I am requiring in my spec_helper.js
So for some reason even though in my spec_helper I am trying to load the BackboneJS application for the testing environment it is not able to find it.
Any thoughts/ideas that I should try to get this communicating/working?
--Mike Riley
I figured this out. The problem was that it was not finding the file under app/assets/javascripts/ correctly. I needed to do this at the top of the spec/javascripts/app_specific/itapp/models/post_spec.js file:
//= require app_specific/itapp/models/post
Once I did that it was able to find the associated code that I am testing against. I will need to work a bit more to clean up the path in a spec_helper.js file, but I am no longer blocked on this.

Yo error encode not defined when generating webapp

I get the following when I run yo webapp from the cmd line after following http://www.youtube.com/watch?feature=player_embedded&v=zBt2g9ekiug to about 3 minutes. Has anyone seen this before?
C:\Users\L\AppData\Roaming\npm\node_modules\generator-webapp\node_modules\cheeri
o\node_modules\entities\index.js:36
return encode[level](data);
^
ReferenceError: encode is not defined
at Object.exports.encode (C:\Users\L\AppData\Roaming\npm\node_modules\genera
tor-webapp\node_modules\cheerio\node_modules\entities\index.js:36:9)
at exports.encode (C:\Users\L\AppData\Roaming\npm\node_modules\generator-web
app\node_modules\cheerio\lib\utils.js:41:50)
at formatAttrs (C:\Users\L\AppData\Roaming\npm\node_modules\generator-webapp
\node_modules\cheerio\lib\render.js:30:32)
at renderTag (C:\Users\L\AppData\Roaming\npm\node_modules\generator-webapp\n
ode_modules\cheerio\lib\render.js:113:18)
at C:\Users\L\AppData\Roaming\npm\node_modules\generator-webapp\node_modules
\cheerio\lib\render.js:81:17
at Array.forEach (native)
at Function._.each._.forEach (C:\Users\L\AppData\Roaming\npm\node_modules\ge
nerator-webapp\node_modules\cheerio\node_modules\underscore\underscore.js:79:11)
at module.exports (C:\Users\L\AppData\Roaming\npm\node_modules\generator-web
app\node_modules\cheerio\lib\render.js:77:5)
at Object.exports.html (C:\Users\L\AppData\Roaming\npm\node_modules\generato
r-webapp\node_modules\cheerio\lib\static.js:40:12)
at Appgenerator.domUpdate (C:\Users\L\AppData\Roaming\npm\node_modules\gener
ator-webapp\node_modules\yeoman-generator\lib\actions\wiring.js:44:14)
I had same issue when follow tutorial with latest Yomen version.
There is typo error in entities library that You can manually fix to complete tutorial:
Open file with error (in your case C:\Users\L\AppData\Roaming\npm\node_modules\generator-webapp\node_modules\cheerio\node_modules\entities\index.js ) and change variable name from inverse to encode
var decode = levels.map(function(l){ return l.normal; }),
decodeStrict = levels.map(function(l){ return l.strict; }),
inverse = levels.map(function(l){ return l.inverse; });
To
var decode = levels.map(function(l){ return l.normal; }),
decodeStrict = levels.map(function(l){ return l.strict; }),
encode = levels.map(function(l){ return l.inverse; });
One workaround is to use the cg-angular yeoman generator:
sudo npm install -g generator-cg-angular
yo cg-angular
Obviously not ideal if you're following a tutorial though.
Also happening in OSX for angular generator:
/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/node_modules/entities/index.js:36
return encode[level](data);
^
ReferenceError: encode is not defined
at Object.exports.encode (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/node_modules/entities/index.js:36:9)
at exports.encode (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/utils.js:41:50)
at formatAttrs (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/render.js:30:32)
at renderTag (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/render.js:114:18)
at /usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/render.js:82:17
at Array.forEach (native)
at Function._.each._.forEach (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/node_modules/underscore/underscore.js:78:11)
at module.exports (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/render.js:78:5)
at Object.exports.html (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/node_modules/cheerio/lib/static.js:40:12)
at Generator.domUpdate (/usr/local/lib/node_modules/generator-angular/node_modules/yeoman-generator/lib/actions/wiring.js:39:14)
The Node module entities just released a new version breaking a dependency (cheerio) of yeoman.
Error seems to originate to cheerio. Issue opened here https://github.com/MatthewMueller/cheerio/pull/382

PhantomJs timeout

I am using Jasmine with PhantomJS to run test cases.
In my typical test case, I make a service call, wait for response and confirm response.
Some requests can return in a few seconds and some can take up to a minute to return.
When ran through PhantomJS, the test case fails for the service call that is supposed to take a minute ( fails because the response is not yet received).
What's interesting is that the test passes when ran through Firefox.
I have tried looking at tcpdump and the headers are same for requests through both browsers, so this looks like a browser timeout issue.
Has anyone had a similar issue ? Any ideas as to where could the timeout be configured ? Or do you think the problem is something else ?
Ah the pain of PhantomJS.
Apparently it turned out that I was using javascript's bind function which is not supported in PhantomJS .
This was causing the test to fail which resulted in messing up state of some global variable( my fault) and hence the failure.
But the root cause was using bind.
Solution: try getting a shim for bind like this from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
I had exactly same issue. All you have to do is add setTimeout to exit
setTimeout(function() {phantom.exit();},20000); // stop after 20 sec ( add this before you request your webpage )
page.open('your url here', function (status) {
// operations here
});

Symfony: issue with switching context

I am using Symfony 1.2 and I have some issues switching context.
This code was working fine:
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration, 'account-prod');
$userToLogin = PcUserPeer::retrieveByEmailAddress("myemail#example.com");
Auth::login($context->getUser(), $userToLogin, false, false);
echo "all done.";
At some point requirements changed and I needed to use the 'public' application before the 'account' one.
Then I changed to:
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
// {{{ new code:
$configuration = ProjectConfiguration::getApplicationConfiguration('public', 'prod', false);
sfContext::createInstance($configuration);
// some code using the public app...
// }}}
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration, 'account-prod');
// {{{ new code:
sfContext::switchTo('account-prod');
// }}}
$userToLogin = PcUserPeer::retrieveByEmailAddress("myemail#example.com");
CustomAuth::login($context->getUser(), $userToLogin, false, false);
echo "all done.";
Basically I added a switchTo call.
After the change, the code got broken and the error message is this:
PHP Fatal error: Call to a member function prepare() on a non-object in /var/www/html/myproj/symfony/storage/sfPDOSessionStorage.class.php on line 109
Thanks for your help,
Dan
Symfony is trying to load the session storage object. I suppose there is a problem with your new environment's configuration.
Check
/apps/public/config/factories.yml
Look for "storage" and try to find out how is it different from the other app's configuration.
Hard to know without a backtrace/more info what is triggering the error. It looks like you are using sessions stored in a database, and that a query related to that is failing.
Try setting the third argument to getApplicationConfiguration to true (which will turn debug on) and see if you get more output.
At a guess, it looks like the account app is using PDO session storage, and is failing to connect to the database or something?

Resources