/test/acceptance/acceptance_helper.rb

https://github.com/amaierhofer/rstat.us · Ruby · 76 lines · 59 code · 17 blank · 0 comment · 2 complexity · c930628a86e20d6b4e20f38542b8415e MD5 · raw file

  1. require_relative '../test_helper'
  2. require 'rack/test'
  3. VCR.config do |c|
  4. c.cassette_library_dir = 'test/data/vcr_cassettes'
  5. c.stub_with :webmock
  6. end
  7. module AcceptanceHelper
  8. require 'capybara/dsl'
  9. require 'capybara/rails'
  10. include Capybara::DSL
  11. include Rack::Test::Methods
  12. include TestHelper
  13. OmniAuth.config.test_mode = true
  14. def app() Rstatus end
  15. def setup
  16. DatabaseCleaner.strategy = :truncation
  17. DatabaseCleaner.clean_with(:truncation)
  18. DatabaseCleaner.start
  19. end
  20. def teardown
  21. DatabaseCleaner.clean
  22. Capybara.reset_sessions!
  23. end
  24. def omni_mock(username, options={})
  25. provider = (options[:provider] || :twitter).to_sym
  26. return OmniAuth.config.add_mock(provider, auth_response(username, options))
  27. end
  28. def log_in(user, uid = 12345)
  29. if user.is_a? User
  30. user = user.username
  31. end
  32. omni_mock(user, {:uid => uid})
  33. visit '/auth/twitter'
  34. end
  35. def log_in_email(user)
  36. User.stubs(:authenticate).returns(user)
  37. visit "/login"
  38. within("form") do
  39. fill_in "username", :with => user.username
  40. fill_in "password", :with => "anything"
  41. end
  42. click_button "Log in"
  43. end
  44. def profile(section = nil)
  45. case section
  46. when "name"
  47. "#profile h3.fn"
  48. when "website"
  49. "#profile .info .website"
  50. when "bio"
  51. "#profile .info p.note"
  52. else
  53. "#profile"
  54. end
  55. end
  56. def flash
  57. "#flash"
  58. end
  59. end