Jasmine environments have a default updateInterval value of 250 that determines how often, in milliseconds, execution of the next spec will be deferred so that the screen can be updated.
var now = new Date().getTime();
if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
self.env.lastUpdate = now;
self.env.setTimeout(function() {
self.next_();
}, 0);
} else {
if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
goAgain = true;
} else {
self.next_();
}
}
Both Chrome and Firefox now require a minimum value of one second for setTimeout in a background tab. This basically means that for every 250ms of work that we do, we end up sleeping for 1000ms.
This gist shows one way to tell Jasmine to not even bother trying to update the screen when running in the background.
var foregroundScreenRefreshRate = 1500;
var backgroundScreenRefreshRate = 9000;
jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;
$(window).focus(function() {
jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;
});
$(window).blur(function() {
jasmine.getEnv().updateInterval = backgroundScreenRefreshRate;
});
(Please refer to the gist for the most up-to-date code.)
This code makes Jasmine run at full-speed in a background tab in Chrome, but continue to be updated about once every 2.5 seconds when in a foreground tab. However, using this as-is in Firefox will result in a warning about an unresponsive script, if the tab is inactive. Luckily, you can continue to run Firefox in the foreground fine with this script (good for CI perhaps), or you can just override the dom.max_script_run_time variable to never get that warning, or you can set updateInterval to something less than the default 10 second max script run time.
Helps
*Is there a way to change the URL that CCRB pulls from when it builds?
"Use Jenkins" (we will be standardizing on Jenkins in the near future anyway)
Apparently the answer has been found successfully in the past by grepping through the Ruby portion of the CCRB source.
Interesting
Hack For Change, sponsored by Change.org is inviting engineers and designers to spend 24 hours to build a web or mobile app that can help advance positive change. Top-rated hacks will be awarded a total of $10,000 to ensure their continued success and will gain recognition through widespread media coverage and promotion. http://hackforchange.com
Guiderails: Pivotal's Rails 3 Templates, has been made publicly available on GitHub. https://github.com/pivotal/guiderails
While there is not consensus on how hash tags in URLs that are being redirected should be handled, Safari stands apart from most other modern browsers by throwing them away entirely.
When configuring a new project for Jenkins, remember to specify the branch to build, otherwise Jenkins will try to pull and build all branches from the repo.
Jasmine has a bug in its "runs and waits for" construct that causes it to ignore changes to the defaults for the timer and message on the "waits for" block.
Help!
Jasmine fixtures A Pivot was bothered by the occasionally stale state of Jasmine .html fixtures. If you're following a workflow similar to the recent Jasmine Railscast then your fixture files will undoubtable deviate from the 'reality' of your application. JB posted a solution that address the issue of quickly generating and loading .html fixture files, but this Pivot's concern was having to manually kick off that process. It seems like watchr would be a good tool to monitor app/views and call one's fixture generation process.
encoding of regular expressions in 1.9
Executing regular expressions over input of unknown encodings has caused headaches for people using Ruby 1.9. When the encoding of the regex and input differ Ruby throws an Encoding::CompatibilityError. The only solution we've seen is to change the encoding of either the input or expression to match the other, as seen here.
Ask for Help
"Anyone using Selenium 2 and Webdriver?"
One of our internal projects is using it.
"How to stop time in Jasmine?"
There were a couple suggestions:
- use a global function, such as 'now'
- send in your own clock object
"Whurl standalone, or more dynos?"
Apparently Whurl is running on a single dyno at Heroku, so a single bad request can tie up Whurl until the request times out. Where are you TildeWill?
"What's this called?"
Imagin these are records in a relational database, with the records on the left having a one to many relationship with the records on the right. How would you google this?

The 3.0.2 update to rails made a change in active support that creates an interference pattern failure in the jasmine-gem. Not jasmine, itself, mind you, just the standalone server that runs the jasmine tests, and not the server, but just the report runner. Thus, your tests are all green, but the jasmine suite fails anyway. You might see this error:
undefined method `merge' for #<JSON::Pure::Generator::State:0x102181890> (NoMethodError)
The selenium driver inside the jasmine gem is loadingjson_pureunless it can find an already loaded JSON class. json_pure was hacked by rails for other reasons, but it breaks JSON.generate. Madness ensues.
To fix this, you need to use something other than json_pure, at least in your test suite. The fix, fortunately, is pretty simple. Add the following line to your Gemfile
gem "json", "1.4.6"
This will load the json gem built with native extensions. The version number is not necessary to fix this problem, but we try to lock down versions as a standard practice.
This was maddeningly painful to pinpoint. I'm not sure if there's a long term solution to the problem either. You need a JSON library, but so do many others. Monkey patching the class seems really handy, but is prone to break behaviors.
Is it possible in Jasmine to spy on a getter such as
myObject[key]? We want to know when local storage is accessed.
No. Jasmine's spyOn only works with functions, and in JavaScript getters are not implemented as functions.
Local storage has a functionally equivalent getValue function, which you can spy on, but the spy is not triggered when you access the value via [].
Interesting:
On unicorn, the random number generator is seeded before the fork. So if you are depending on a set of unicorns to generate different random numbers, you need to reseed the random number generator manually after the fork.
If you want to make absolutely sure you aren't generating any queries in your Rails views, try no_querying_views - which explodes if your query comes from view code.
Other ways to track down inefficient queries that folks have successfully used: bullet and query_reviewer
Skype 5 beta is out for Mac, which allows group video chat. Everyone must be on the beta for it to work.
Ask for Help
- I asked if there's a date library in Ruby as rich as Java's JODA
Suggestions included Chronic and RI_CAL though I'm hoping for something that can represent arbitrary periods (ranges?) of time JODA and handles interval calculation and other such date/time arithmetic.
- is(':visible') doesn't always work as expected in Jasmine
One project reported that using this to as part of a Jasmine spec to ensure that an element becomes visible doesn't appear to be reliable.
- Annotate and Git History failed for a team using Rubymine 2.0.2 and git 1.7.2.1 in combination with svn.
They solved the problem by downgrading to git 1.7.1.1:
I followed instructions here to create a local set of portfiles:
http://guide.macports.org/#development.local-repositories and grabbed the older portfile from here:
https://trac.macports.org/browser/trunk/dports/devel/git-core?rev=69357
After I could do a port search git-core and have 1.7.1.1 show up, I was able to
sudo port deactivate git-core @1.7.2_0+doc+svnandsudo port install git-core @1.7.1.1+doc+svn
One person was experienced compile errors when installing
memprofon Ubuntu, fortunately somebody else had gotten this working before and offered to help him through thee.A team noticed that Bundler ran multiple (4) times on CI taking nearly 11mins overall and wanted to know to make Bundler run only once
It was suggested that the problem may be due to the way they'd setup their preinitializer.rb and they should move the bundle install into a Rake task.
if ENV['IS_CI_BOX']
puts "IS_CI_BOX is set, running bundle install..."
system('bundle install') || raise("'bundle install' command failed. Install bundler with gem install bundler.")
end
It was pointed out that they should make sure their Gemfile.lock file is checked into version control, which it was. Additionally Bundler 1.0.0 RC1 will allow isolating gems to a local path using bundle install path --disable-shared-gems
Interesting Things
- The Facebook Graph API doesn't appear to implement OAuth 2.0 properly/completely so it doesn't work with the OAuth2 gem
- One Pivot noticed that the version of ImageMagick installed on the default EngineYard solo image is out of date and had to upgrade this manually.
Interesting Things
- One team noticed an odd error when they mistyped a
Thorconstant name.
ArgumentError: Thor is not missing constant Sandbox!.
This appears to due to how #const_missing in activesupport handles nested constant names. Specifically when trying to reference one nested constant from within another nested constant that isn't its parent:
Curiously the spec that exposed the previous issue also returned this odd summary:
0 examples, 1 failure, -1 passed
This is also similar to another standup blog post from almost a year ago.
- When using JB's technique to save fixtures
for Jasmine in controller specs, considering naming all your examples that create fixtures identically. This way you can easily run just these examples to regenerate your fixtures with something like
spec -e 'should generate a fixture for jasmine'
Since the language of the new iPhone UI Automation component is JavaScript I figured the easiest way to organize tests is to use a JavaScript testing framework, such as Jasmine. So, I created jasmine-iphone, which is little more than a few simple scripts to make UI Automation and Jasmine play nice.
Once you clone jasmine-iphone from GitHub (it includes Jasmine as a submodule, so be sure to git submodule init && git submodule update) you can copy the example-suite.js file, import your spec files, point Instruments at your suite.js and go.
As an example, I set up a trivial example in the Cedar project. The directory structure looks like this:
Project Directory
\- Spec
\- UIAutomation
\- jasmine-iphone <--- submodule
\- jasmine <--- nested submodule
\- suite.js
\- thing-spec.js
\- other-thing-spec.js
The suite.js file is relatively simple (note that I moved it up one directory from where the example-suite.js file is, so the #import statements are slightly different):
#import "jasmine-iphone/jasmine-uiautomation.js" #import "jasmine-iphone/jasmine-uiautomation-reporter.js" // Import your JS spec files here. #import "thing-spec.js" #import "other-thing-spec.js" jasmine.getEnv().addReporter(new jasmine.UIAutomation.Reporter()); jasmine.getEnv().execute();
You can write the specs themselves the same way you'd write Jasmine specs for anything else. The UIAutomation subclass of the Jasmine Reporter takes care of marking the start of each spec, as well as reporting if it passes or fails. You'll need to use the UIAutomation classes and methods for driving your application's state, of course.
That's it. Try it out and see what you think.
Interesting Things
Jasmine bundled with RubyRacer
Jasmine is now optionally bundled with the RubyRacer gem. This lets you run Jasmine tests through Google's V8 engine in a browser-less environment. Similarly, some Pivots paired Jasmine with Johnson and env.js to produce JazzMoney. Right now, JazzMoney is the only headless testing tool for Ruby that has DOM support, but I'm sure RubyRacer has that in mind. You can find JazzMoney here.
Help
Does anyone know how to run specs with a certain name? We're using RSpec to generate fixtures for our Jasmine tests and want those to be updated right before we run our Jasmine task.
You can set SPEC_OPTS with the 'e' flag and give it a string to match test names. Something like this:
rake spec SPEC_OPTS='-e "should generate a fixture"'
