Skip to content

Instantly share code, notes, and snippets.

import * as someReduxActions from '../actions/someReduxActions'
beforeEach( () => {
sinon.stub(someReduxActions, 'fetchSomething').returns('we have results')
})

Keybase proof

I hereby claim:

  • I am timwingfield on github.
  • I am timwingfield (https://keybase.io/timwingfield) on keybase.
  • I have a public key whose fingerprint is 15D3 BF38 A26A 376D F742 2293 22A1 893F 2406 65FB

To claim this, I am signing this object:

@timwingfield
timwingfield / jqSelectorTest.js
Created March 7, 2014 14:42
testing a jquery selector value
//The method under test
on: function(event, fn){
$("#" + this.currentView.modalId).on(event, fn);
}
//The Jasmine spec
describe("account/company", function() {
Given(function() { this.view = { modalId: "modalId" } });
Given(function() { subject = new PopupView(this.view) });
extend 'the.models.OurModel', class OurModel extends Backbone.Model
url: ->
"#{relativeUrlRoot}/some_controller/some_action#{@get 'channel_type'}_data/#{@get 'end_point_id'}"
parse: (response) ->
response.id = "#{response.end_point_id}_#{response.channel_type}"
response
@timwingfield
timwingfield / jasmineSpySpike.js
Created August 22, 2012 16:35
constructor spying spike
describe("Spying on a window object", function() {
describe("working with the object", function() {
beforeEach(function () {
this.name = "Spongebob";
this.subject = new Klass(this.name);
});
it("should have properties", function() {
expect(this.subject.properties).toBeDefined();
});
@timwingfield
timwingfield / revealing module pattern
Created July 5, 2012 22:28
revealing module in javascript
ProjectNamespace.Helpers.Converters = (function() {
var convertToDate, convertToFloat, convertToInteger, isValidDate;
isValidDate = function(d) {
if (Object.prototype.toString.call(d) === "[object Date]") {
return !isNaN(d.getTime());
}
return false;
};
convertToDate = function(input) {
var d;
@timwingfield
timwingfield / gist:1761174
Created February 7, 2012 18:43
Our little Parent initializer
describe Parent do
describe "initializing a new parent" do
context "and using a hash" do
Given { @hash = {:id => "55", :name => "Spongebob" } }
When { @parent = Parent.new @hash }
Then { @parent.name.should == "Spongebob" }
Then { @parent.id.should == "55" }
end
context "and not using a hash" do
describe "app.Agent", ->
Given -> @car = new Backbone.Model
Given -> spyOn(@car, "get")
Given -> @car.get.when('phone').thenReturn("123-456-789")
Given -> @car.get.when('name').thenReturn("juice")
Then -> expect(@car.get).toHaveBeenCalledWith('phone')
Then -> expect(@car.get).toHaveBeenCalledWith(jasmine.any(String))
Then -> expect(@car.get).toHaveBeenCalledWith jasmine.argThat (arg) ->
arg.length < 5
@timwingfield
timwingfield / zsh_battery_icon.rb
Created September 5, 2011 19:04
zsh script to set an icon on my prompt based on battery charge/status
#!/usr/bin/env ruby
# encoding: UTF-8
# example for getting the battery settings https://gist.github.com/176025
info = `ioreg -rc "AppleSmartBattery"`
battery = %w(ExternalConnected CurrentCapacity MaxCapacity IsCharging).inject({}) do |hash, property|
hash[property.to_sym] = info[/"#{property}" = (.*)$/, 1]; hash
end
@timwingfield
timwingfield / MoqSetupMock.cs
Created July 27, 2011 06:12
Setting up a Mock with Moq
[TestFixture]
public class When_saving_a_vehicle_in_the_view_model_with_a_vehicle : Specification
{
private VehicleViewModel _viewModel;
private Mock<IVehicleRepository> _repository;
protected override void before_each()
{
_repository = new Mock<IVehicleRepository>();
_viewModel = new VehicleViewModel(_repository.Object);