Module: Glib::TestHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/glib/test_helpers.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

HOST =
'www.lvh.me:3000'

Instance Method Summary collapse

Instance Method Details

#crawl_json_pages(user, check_result: true, log_file: nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/glib/test_helpers.rb', line 34

def crawl_json_pages(user, check_result: true, log_file: nil, &block)
  __execute_crawler(user, check_result: true) do |router, http|
    path = user[:path] ? "#{user[:path]}?format=json" : '/users/me?format=json&redirect=default'
    router.host = HOST
    router.step(
      http,
      'onClick' => {
        'action' => user[:action] || 'initiate_navigation',
        'url' => user[:url] || "http://#{HOST}#{path}"
      }
    )
  end
end

#logoutObject



54
55
56
57
# File 'lib/glib/test_helpers.rb', line 54

def logout
  delete logout_url
  assert_response :success
end

#logout_urlObject



59
60
61
# File 'lib/glib/test_helpers.rb', line 59

def logout_url
  "http://#{HOST}/users/sign_out.json"
end

#response_assert_equalObject

LOG_DIR = File.expand_path(

File.join(File.dirname(__FILE__), 'integration/json_ui_crawler_test_results')

)



28
29
30
31
32
# File 'lib/glib/test_helpers.rb', line 28

def response_assert_equal
  expected = __get_previous_result_from_git
  result = __log_controller_data(response.body)
  assert_equal JSON.parse(expected), JSON.parse(result), "Result mismatch! #{__git_is_available? ? `git diff #{__controller_log_dir}/#{__controller_log_file}` : ''}"
end

#retrace_json_pages(user, guiding_routers:) ⇒ Object



48
49
50
51
52
# File 'lib/glib/test_helpers.rb', line 48

def retrace_json_pages(user, guiding_routers:)
  __execute_crawler(user, check_result: true) do |router, http|
    router.follow(http, guiding_routers)
  end
end