Skip to content

Commit 9f03407

Browse files
committed
Adding two more tests, new factories + debugger.
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.
1 parent ca1ffff commit 9f03407

8 files changed

Lines changed: 52 additions & 32 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ group :test do
2525
gem "rspec", "~>2.1.0"
2626
gem "webrat", "~>0.7.1"
2727
gem "steak", "~>1.0.0"
28+
29+
gem "ruby-debug"
2830
end

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ GEM
1414
selenium-webdriver (>= 0.0.3)
1515
childprocess (0.1.4)
1616
ffi (~> 0.6.3)
17+
columnize (0.3.2)
1718
configuration (1.2.0)
1819
culerity (0.2.12)
1920
database_cleaner (0.6.0)
@@ -29,6 +30,7 @@ GEM
2930
launchy (0.3.7)
3031
configuration (>= 0.0.5)
3132
rake (>= 0.8.1)
33+
linecache (0.43)
3234
mail (2.2.10)
3335
activesupport (>= 2.3.6)
3436
i18n (~> 0.4.1)
@@ -62,6 +64,11 @@ GEM
6264
rspec-expectations (2.1.0)
6365
diff-lcs (~> 1.1.2)
6466
rspec-mocks (2.1.0)
67+
ruby-debug (0.10.4)
68+
columnize (>= 0.1)
69+
ruby-debug-base (~> 0.10.4.0)
70+
ruby-debug-base (0.10.4)
71+
linecache (>= 0.3)
6572
rubyzip (0.9.4)
6673
selenium-webdriver (0.1.0)
6774
childprocess (= 0.1.4)
@@ -98,6 +105,7 @@ DEPENDENCIES
98105
rack-flash (~> 0.1.1)
99106
rdiscount (~> 1.6.5)
100107
rspec (~> 2.1.0)
108+
ruby-debug
101109
sinatra (~> 1.1)
102110
steak (~> 1.0.0)
103111
webrat (~> 0.7.1)

features/hacker.feature

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
Feature: Hacker management
2-
Scenario: Users can register
3-
Given I'm not logged in
4-
And I go to the new hacker page
5-
And I fill in "Email" with "steve@example.com"
6-
And I fill in "Username" with "steve"
7-
And I fill in "Password" with "foobar"
8-
And I fill in "Confirm Password" with "foobar"
9-
When I press "Create account"
10-
Then I should see "Account created."
11-
And I should be on the main page
12-
Scenario: No duplicate usernames
13-
Given there's a hacker with the username "steve"
14-
And I'm not logged in
15-
And I go to the new hacker page
16-
And I fill in "Email" with "steve@example.com"
17-
And I fill in "Username" with "steve"
18-
And I fill in "Password" with "foobar"
19-
And I fill in "Confirm Password" with "foobar"
20-
When I press "Create account"
21-
Then I should see "There were some problems"
22-
And I should be on the new hacker page
23-
Scenario: Hacker pages
24-
Given there's a hacker with the username "steve"
25-
When I go to the hacker page for "steve"
26-
Then I should see "steve's page"
27-
Scenario: Going to your profile
28-
Given I'm logged in as "steve"
29-
And I go to the home page
30-
When I follow "Your Page"
31-
Then I should be on the hacker page for "steve"
32-
And I should not see "Send steve a message"
332
Scenario: Following Hackers
343
Given there's a hacker with the username "fela"
354
And I'm logged in as "steve"

helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def current_user
2323
#this method returns true if we're logged in, and false if we're not
2424
def logged_in?
2525
#pretty easy, just check the session
26-
return session[:hacker_id] != nil
26+
current_user != nil
2727
end
2828

2929
#this helper checks if the current_user is admin, and redirects them if they're not

spec/acceptance/hacker_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@
1616
should_be_on "/"
1717
end
1818

19+
scenario "visit a profile" do
20+
hacker = Factory(:hacker, :username => "steve")
21+
visit "/hackers/steve"
22+
page.should have_content "steve's page"
23+
end
24+
25+
scenario "visit your profile" do
26+
@hacker = Factory(:hacker)
27+
log_in @hacker
28+
29+
visit "/"
30+
click_link "Your Page"
31+
should_be_on "/hackers/#{@hacker.username}"
32+
page.should_not have_content "Send steve a message"
33+
end
34+
1935
end

spec/acceptance/support/helpers.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ def should_be_on(path)
55
def should_not_be_on(path)
66
page.current_url.should_not match(Regexp.new(path))
77
end
8+
9+
def log_in(hacker)
10+
visit "/login"
11+
fill_in "username", :with => hacker.username
12+
fill_in "password", :with => hacker.password
13+
click_button "Log in"
14+
end

spec/factories.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#These are the factory_girl factories, for testing.
2+
#Learn more about factory_girl here: http://github.com/thoughtbot/factory_girl
3+
4+
#this is an email sequence, so we don't use the same email over and over!
5+
Factory.sequence :email do |n|
6+
"user#{n}@example.com"
7+
end
8+
9+
#this factory defines a hacker
10+
Factory.define :hacker do |u|
11+
u.username "steve"
12+
u.email { Factory.next(:email) }
13+
u.password "foobar"
14+
#we need to set the password_confirmation to the same value as the password
15+
u.password_confirmation {|user| user.password }
16+
u.admin false
17+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'database_cleaner'
44
require 'factory_girl'
55

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

78
RSpec.configure do |config|
89
config.mock_with :rspec

0 commit comments

Comments
 (0)