Skip to content

Commit

Permalink
Adding two more tests, new factories + debugger.
Browse files Browse the repository at this point in the history
Sweet stuff, moving more tests over. Also, I've decided I'm going to
re-work the factories a bit, and put them in one file. Finally, I've
seen the light about ruby-debugger, so i'm adding it in, since we're
1.8.7.
  • Loading branch information
steveklabnik committed Nov 25, 2010
1 parent ca1ffff commit 9f03407
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -25,4 +25,6 @@ group :test do
gem "rspec", "~>2.1.0"
gem "webrat", "~>0.7.1"
gem "steak", "~>1.0.0"

gem "ruby-debug"
end
8 changes: 8 additions & 0 deletions Gemfile.lock
Expand Up @@ -14,6 +14,7 @@ GEM
selenium-webdriver (>= 0.0.3)
childprocess (0.1.4)
ffi (~> 0.6.3)
columnize (0.3.2)
configuration (1.2.0)
culerity (0.2.12)
database_cleaner (0.6.0)
Expand All @@ -29,6 +30,7 @@ GEM
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
linecache (0.43)
mail (2.2.10)
activesupport (>= 2.3.6)
i18n (~> 0.4.1)
Expand Down Expand Up @@ -62,6 +64,11 @@ GEM
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rubyzip (0.9.4)
selenium-webdriver (0.1.0)
childprocess (= 0.1.4)
Expand Down Expand Up @@ -98,6 +105,7 @@ DEPENDENCIES
rack-flash (~> 0.1.1)
rdiscount (~> 1.6.5)
rspec (~> 2.1.0)
ruby-debug
sinatra (~> 1.1)
steak (~> 1.0.0)
webrat (~> 0.7.1)
31 changes: 0 additions & 31 deletions features/hacker.feature
@@ -1,35 +1,4 @@
Feature: Hacker management
Scenario: Users can register
Given I'm not logged in
And I go to the new hacker page
And I fill in "Email" with "steve@example.com"
And I fill in "Username" with "steve"
And I fill in "Password" with "foobar"
And I fill in "Confirm Password" with "foobar"
When I press "Create account"
Then I should see "Account created."
And I should be on the main page
Scenario: No duplicate usernames
Given there's a hacker with the username "steve"
And I'm not logged in
And I go to the new hacker page
And I fill in "Email" with "steve@example.com"
And I fill in "Username" with "steve"
And I fill in "Password" with "foobar"
And I fill in "Confirm Password" with "foobar"
When I press "Create account"
Then I should see "There were some problems"
And I should be on the new hacker page
Scenario: Hacker pages
Given there's a hacker with the username "steve"
When I go to the hacker page for "steve"
Then I should see "steve's page"
Scenario: Going to your profile
Given I'm logged in as "steve"
And I go to the home page
When I follow "Your Page"
Then I should be on the hacker page for "steve"
And I should not see "Send steve a message"
Scenario: Following Hackers
Given there's a hacker with the username "fela"
And I'm logged in as "steve"
Expand Down
2 changes: 1 addition & 1 deletion helpers.rb
Expand Up @@ -23,7 +23,7 @@ def current_user
#this method returns true if we're logged in, and false if we're not
def logged_in?
#pretty easy, just check the session
return session[:hacker_id] != nil
current_user != nil
end

#this helper checks if the current_user is admin, and redirects them if they're not
Expand Down
16 changes: 16 additions & 0 deletions spec/acceptance/hacker_spec.rb
Expand Up @@ -16,4 +16,20 @@
should_be_on "/"
end

scenario "visit a profile" do
hacker = Factory(:hacker, :username => "steve")
visit "/hackers/steve"
page.should have_content "steve's page"
end

scenario "visit your profile" do
@hacker = Factory(:hacker)
log_in @hacker

visit "/"
click_link "Your Page"
should_be_on "/hackers/#{@hacker.username}"
page.should_not have_content "Send steve a message"
end

end
7 changes: 7 additions & 0 deletions spec/acceptance/support/helpers.rb
Expand Up @@ -5,3 +5,10 @@ def should_be_on(path)
def should_not_be_on(path)
page.current_url.should_not match(Regexp.new(path))
end

def log_in(hacker)
visit "/login"
fill_in "username", :with => hacker.username
fill_in "password", :with => hacker.password
click_button "Log in"
end
17 changes: 17 additions & 0 deletions spec/factories.rb
@@ -0,0 +1,17 @@
#These are the factory_girl factories, for testing.
#Learn more about factory_girl here: http://github.com/thoughtbot/factory_girl

#this is an email sequence, so we don't use the same email over and over!
Factory.sequence :email do |n|
"user#{n}@example.com"
end

#this factory defines a hacker
Factory.define :hacker do |u|
u.username "steve"
u.email { Factory.next(:email) }
u.password "foobar"
#we need to set the password_confirmation to the same value as the password
u.password_confirmation {|user| user.password }
u.admin false
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -3,6 +3,7 @@
require 'database_cleaner'
require 'factory_girl'

require "#{File.dirname(__FILE__)}/factories.rb"

RSpec.configure do |config|
config.mock_with :rspec
Expand Down

0 comments on commit 9f03407

Please sign in to comment.