Going to start playing with virtualenvwrapper:
http://virtualenvwrapper.readthedocs.org/en/latest/index.html
Tuesday, December 31, 2013
Updating Python On Mac OS X
The Python that comes with OS X is a bit out of date, so I decided to update it. After poking around the internet for a while, I came across some pretty good docs:
Basically, I ran:
$ brew install python
I got Python along with Pip and Distribute, which is awesome. I heard both pieces of software helps you with installing and uninstalling other Python packages.
I then installed virtualenv, a handy dev tool that allows me to create virtual Python environments that do not interfere with each other.
$ pip install virtualenv
In order to see the new version of Python in action, I had to open a new terminal window. Everything looks good. My only complaint is that the version of Python I have now installed is 2.7.5 instead of 2.7.6, so it is a step behind the latest and greatest version. I am going to have to investigate if this is a serious issue or not. I heard 2.7.6 did fix some bugs in 2.7.5, but the user might have to install an updated version of Tcl/Tk to get IDLE working.
Thursday, December 26, 2013
DataSquid Screen Grabs
I have always been interested in data visualization, so for my final project I decided to explore D3.js. After taking a bike ride on Venice Beach, I came up with the following name.
Looking forward to playing with D3.js and other data visualization tools some more! Paper.js looks cool (http://paperjs.org/).
DataSquid allows a user to upload a JSON file that describes relationships with between various nodes. DataSquid then uses D3.js to generate a fun, interactive force directed graph that users can then modify.
Looking forward to playing with D3.js and other data visualization tools some more! Paper.js looks cool (http://paperjs.org/).
Saturday, December 14, 2013
Used JSFiddle For The First Time!
Created my first public fiddle on JSFiddle:
http://jsfiddle.net/cspears2002/vVL99/
A pretty useful tool. I am using it to post my code on StackOverflow, so users can help me get to the bottom of the issue I have been having with implementing a fisheye distortion on the force directed graph. For some reason, the nodes are distorting before the links.
http://jsfiddle.net/cspears2002/vVL99/
A pretty useful tool. I am using it to post my code on StackOverflow, so users can help me get to the bottom of the issue I have been having with implementing a fisheye distortion on the force directed graph. For some reason, the nodes are distorting before the links.
Thursday, December 5, 2013
Stubbing Out A User For Your Rspec Test
How to stub out a user when testing a controller with rspec:
# for controllers
user = User.create(:name => 'user@example.com', :password => 'caplin')
ApplicationController.stub(:current_user).and_return(user)
# for controllers
user = User.create(:name => 'user@example.com', :password => 'caplin')
ApplicationController.stub(:current_user).and_return(user)
Refactoring Rspec/Capybara tests (with a little help from FactoryGirl)
"We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris." - Larry Wall
I am writing a web app using BDD. In order to do just about anything in my app, the user needs to log in, so I was encouraged to write a function that will sign the user every time a rspec test is run. Basically, the code for the features test will end up looking like this:
DataSquid/spec/features/user_logs_in_spec.rb
require 'spec_helper'
feature "signing in" do
before :each do
@user = User.create(:name => 'user@example.com', :password => 'caplin')
end
scenario "user who logs in with correct credentials" do
sign_in(@user)
expect(page).to have_content 'Hi user@example.com'
end
end
First I read this article: http://robots.thoughtbot.com/rspec-integration-tests-with-capybara
Unfortunately, the author did not point out that they used FactoryGirl to work. In your Gemfile, add FactoryGirl:
# For testing
group :test, :development do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem "factory_girl_rails", "~> 4.0"
end
After running 'bundle install', you should be good to go. I then made this file, which holds the sign_in function.
DataSquid/spec/support/features/session_helpers.rb
module Features
module SessionHelpers
def sign_in(user=nil)
user ||= FactoryGirl.create(:user)
visit '/authentications/new'
fill_in 'Login', with: user.name
fill_in 'Password', with: user.password
click_button 'Sign in'
end
end
end
From what I can tell, the code in the file below makes the code in the session_helpers.rb file available to all of the feature tests.
DataSquid/spec/support/features.rb
RSpec.configure do |config|
config.include Features::SessionHelpers, type: :feature
end
Now I have a handy function I can call in my feature tests! Here is the link to my conversation on Stack Overflow about this issue: http://stackoverflow.com/questions/20390072/trouble-with-refactoring-code-for-rspec-feature-tests-in-rails-4.
Subscribe to:
Posts (Atom)