# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper.rb"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

ENV["RAILS_ENV"] = 'test'
require_relative "ajaxify_test/config/environment"

require 'rspec/rails'
require 'rspec-steps'
require 'sqlite3'

require 'haml'

# Add this to load Capybara integration:
require 'capybara/rspec'
require 'capybara/rails'

# require 'capybara/poltergeist'

# Capybara.register_driver :poltergeist do |app|
#   # Specifiying the phantomjs path only for RubyMine which fails to pick it up otherwise
#   Capybara::Poltergeist::Driver.new(app, phantomjs: '/usr/local/bin/phantomjs') #, inspector: true
# end

# Capybara.javascript_driver = :poltergeist
# Capybara.current_driver    = :poltergeist

Capybara.default_selector  = :css
Capybara.default_wait_time = 3

RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  #config.run_all_when_everything_filtered = true
  config.include Capybara::DSL
end


def wait_until_gone css
	page.should have_no_css(css)
end

def wait_for_ajaxify_loaded
  wait_until_gone ".ajaxify_loader"
end

def click_browser_back_button
	page.execute_script("window.history.back()")
end

def click_browser_forward_button
	page.execute_script("window.history.forward()")
end

def ensure_layout_not_reloaded
	find('body')['data-id'].to_s.should eq(@layout_id), "Layout has been reloaded but shouldn't"
end

def should_have_content content
	page.should have_css('#main', text: content)
end

def should_have_notice notice
	page.should have_css('#notice', text: notice)
end

def disable_push_state
	page.execute_script("window.history.pushState = null;")
end

def current_hash
	URI.parse(current_url).fragment.to_s
end

def hash_path_should_be path
	current_hash.should == path
	current_path.should == '/'
end

def push_state_path_should_be path
	current_hash.should == ''
	current_path.should == path
end

