Skip to content

Commit

Permalink
Merge pull request hotsh#711 from carols10cents/stupid_tests
Browse files Browse the repository at this point in the history
Stupid tests
  • Loading branch information
steveklabnik committed Nov 4, 2012
2 parents 1a2d730 + 691c968 commit cbc3924
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 48 deletions.
33 changes: 33 additions & 0 deletions test/acceptance/acceptance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,37 @@ def search_for(query)
fill_in "search", :with => query
click_button "Search"
end

def heisenbug_log
old_rails_logger = Rails.logger
old_action_controller_logger = ActionController::Base.logger

logfile = 'log/heisenbug.log'
new_logger = Logger.new(logfile)
new_logger.level = Logger::DEBUG

Rails.logger = new_logger
ActionController::Base.logger = new_logger

begin
yield
rescue Heisenbug
puts
puts "Start of Heisenbug logging ======================================"
puts File.read logfile
puts "================"
puts body
puts "End of Heisenbug logging ========================================"
puts
puts "Congratulations!! You've seen an incidence of a HEISENBUG we're"
puts "tracking. Please copy the output from Start to End and paste it"
puts "in a comment on https://github.com/hotsh/rstat.us/issues/479"
ensure
File.delete logfile
Rails::logger = old_rails_logger
ActionController::Base.logger = old_action_controller_logger
end
end
end

class Heisenbug < StandardError; end
24 changes: 15 additions & 9 deletions test/acceptance/following_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@
end

it "unfollows another user" do
skip "Passing locally but failing on Travis and we don't know why"
log_in_as_some_user
heisenbug_log do
log_in_as_some_user

u2 = Fabricate(:user)
a2 = Fabricate(:authorization, :user => u2)
u2 = Fabricate(:user)
a2 = Fabricate(:authorization, :user => u2)

@u.follow! u2.feed
@u.follow! u2.feed

visit "/users/#{@u.username}/following"
click_button "unfollow-#{u2.feed.id}"
visit "/users/#{@u.username}/following"

if has_button? "unfollow-#{u2.feed.id}"
click_button "unfollow-#{u2.feed.id}"
else
raise Heisenbug
end

within flash do
assert has_content? "No longer following #{u2.username}"
within flash do
assert has_content? "No longer following #{u2.username}"
end
end
end
end
Expand Down
36 changes: 20 additions & 16 deletions test/acceptance/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@
end

it "has the user's updates on the page in reverse chronological order" do
skip "Passing locally but failing on Travis and we don't know why"

u = Fabricate(:user)
update1 = Fabricate(:update,
:text => "This is a message posted yesterday",
:author => u.author,
:created_at => 1.day.ago)
update2 = Fabricate(:update,
:text => "This is a message posted last week",
:author => u.author,
:created_at => 1.week.ago)
u.feed.updates << update1
u.feed.updates << update2

visit "/users/#{u.username}"
assert_match /#{update1.text}.*#{update2.text}/m, page.body
heisenbug_log do
u = Fabricate(:user)
update1 = Fabricate(:update,
:text => "This is a message posted yesterday",
:author => u.author,
:created_at => 1.day.ago)
update2 = Fabricate(:update,
:text => "This is a message posted last week",
:author => u.author,
:created_at => 1.week.ago)
u.feed.updates << update1
u.feed.updates << update2

visit "/users/#{u.username}"
if page.body.match /#{update1.text}.*#{update2.text}/m
assert_match /#{update1.text}.*#{update2.text}/m, page.body
else
raise Heisenbug
end
end
end

it "responds with HTML by default if Accept header is */*" do
Expand Down
70 changes: 47 additions & 23 deletions test/acceptance/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,36 @@
end

it "destroys own update" do
skip "Passing locally but failing on Travis and we don't know why"
visit "/users/#{@u.username}"
click_button "I Regret This"

within 'div.flash' do
assert has_content? "Update Deleted!"
heisenbug_log do
visit "/users/#{@u.username}"
if has_button? "I Regret This"
click_button "I Regret This"
else
raise Heisenbug
end

within 'div.flash' do
assert has_content? "Update Deleted!"
end
end
end

it "doesn't destroy not own update" do
skip "Passing locally but failing on Travis and we don't know why"
author = Fabricate(:author)
visit "/users/#{@u.username}"
heisenbug_log do
author = Fabricate(:author)
visit "/users/#{@u.username}"

Update.any_instance.stubs(:author).returns(author)
Update.any_instance.stubs(:author).returns(author)

click_button "I Regret This"
if has_button? "I Regret This"
click_button "I Regret This"
else
raise Heisenbug
end

within 'div.flash' do
assert has_content? "I'm afraid I can't let you do that, #{@u.username}."
within 'div.flash' do
assert has_content? "I'm afraid I can't let you do that, #{@u.username}."
end
end
end
end
Expand All @@ -158,19 +168,33 @@
end

it "clicks the reply link from update on a user's page" do
skip "Passing locally but failing on Travis and we don't know why"
visit "/users/#{@u2.username}"
click_link "reply"
assert_match "What's Going On?", page.body
assert_match "foo", page.body
heisenbug_log do
visit "/users/#{@u2.username}"

if has_link? "reply"
click_link "reply"
else
raise Heisenbug
end

assert_match "What's Going On?", page.body
assert_match "foo", page.body
end
end

it "clicks the share link from update on a user's page" do
skip "Passing locally but failing on Travis and we don't know why"
visit "/users/#{@u2.username}"
click_link "share"
assert_match "What's Going On?", page.body
assert_match "RS @#{@u2.username}: #{@u2.feed.updates.last.text}", page.body
heisenbug_log do
visit "/users/#{@u2.username}"

if has_link? "share"
click_link "share"
else
raise Heisenbug
end

assert_match "What's Going On?", page.body
assert_match "RS @#{@u2.username}: #{@u2.feed.updates.last.text}", page.body
end
end
end

Expand Down

0 comments on commit cbc3924

Please sign in to comment.