testing snippets

How to test Rails routing with RSpec

Tagged testing, rspec, routing, routes  Languages ruby
route_for(:controller => 'categories', :action => 'show', :permalink => ['one', 'two', 'three']).should.equal '/one/two/three'
route_for(:controller => 'categories', :action => 'index').should.equal '/'
      
params_from(:get, "/").should.equal {:controller => "categories", :action => "index"}
params_from(:get, "/something/").should.equal {:controller => "categories", :action => "show", :permalink => ["something"]}

The test_spec_on_rails plugin also allow you to test routing and much more, see the docs for more information.

Test functionality in isolation with Autospec

Tagged autotest, testing, bdd, tdd, autospec, zentest  Languages ruby

This configuration will make autospec run "spec/models/xyz_spec" when a file in "lib/xyz/ is modified". No other tests are run.

Put the following code in ./.autotest:

Autotest.add_hook :initialize do |at|
  at.clear_mappings
  %w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)}

  at.add_mapping(%r%^lib/xyz/.*\.rb$%) {
    at.files_matching %r%^spec/models/xyz_spec\.rb$%
#
# Uncomment if more tests are needed...
# +   at.files_matching %r%^spec/models/xyz_spec\.rb$%
#
  }
end

How to test a Sinatra webapp with Rspec

Tagged sinatra, rspec, spec, testing, bdd  Languages ruby

Create spec/app_spec.rb and put the following in it:

require 'sinatra'
require 'spec/interop/test'
require 'sinatra/test/unit'

require 'app'
require 'test/spec'

set :environment, :test

describe 'The HelloWorld App' do
  before(:each) do
    set :views => File.join(File.dirname(__FILE__), "..", "views")
  end

  it "says hello" do
    get '/'
    response.should.be.ok
    response.body.should.equal 'Hello World'
  end
end

Then run the test:

spec spec/app_spec.rb

The Scientific Method

Tagged growth, hypothesis, marketing, method, research, scientific, testing  Languages 

“The Scientific Method” from https://www.reforge.com/blog/run-growth-team-like-a-scientist

Inputs

  1. Question: What do I want to understand?
  2. Hypothesis: What is my proposed explanation to the question?
  3. Experiment: Design an experiment to test the hypothesis.

Outputs

  1. Observation: Observe the experiment and record results.
  2. Analysis: Interpret the results.

Notes

the qualitative inputs - question, hypothesis, and experiment design - are the most important steps of the process. If you get these steps right, you increase your chances of running successful experiments that produce valid results and actionable insights.

So, what separates the good growth teams (and research labs) from the great ones?

It’s the quality of the questions they ask, the hypotheses they come up with, and how they construct their experiments.

A one-day or one-week in vitro test using a landing page builder to mockup a subscription pricing page, driving traffic to it via ads, and measuring conversion rates against current pricing may have quickly revealed that a subscription pricing model wasn’t appealing to their customer base.

the point is to use an in vitro test to get validation that an in vivo test is worth the additional resources. Tools like Unbounce, Optimizely, and paid advertising make these kinds of in vitro tests easy and fast.

One of my favorite mentors, Anantha Katragadda, told me when I was starting out in growth that if I couldn’t think of a way to fake a product experience in order to get validating data, I simply wasn’t trying hard enough.

To publish a paper, every result must disprove the null hypothesis. This means that you prove, with statistical significance, that the result you are seeing is not due to random chance or biased observation