Skip to content

Instantly share code, notes, and snippets.

@bbasata
Created October 28, 2011 19:53
Show Gist options
  • Save bbasata/1323368 to your computer and use it in GitHub Desktop.
Save bbasata/1323368 to your computer and use it in GitHub Desktop.
First draft: wondering if anyone else would love to see a RSpec-like lazy-initializing let() function introduced into @jasminebdd
function lazy(fn) {
return _.once(fn);
}
describe('Expired Item View', function() {
var item, view, rendered;
beforeEach(function() {
item = lazy(function() { return {}; });
view = lazy(function() { return new APP.Views.ExpiredItem({ item: item() }); });
rendered = lazy(function() { return view().render().el });
});
it('renders as a list item', function() {
expect($(rendered())).toBe('li');
});
context('when it can be renewed', function() {
beforeEach(function() {
item = lazy(function() { return { renewable: true }; });
});
it('has the renewable class', function() {
expect($(rendered()).toBe('li.renewable');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment