This commit is contained in:
nilsding 2014-11-17 23:25:28 +01:00
parent cae59cd5b4
commit 76e6b8f5ec
8 changed files with 71 additions and 8 deletions

View file

@ -41,6 +41,8 @@ group :development, :test do
gem 'shoulda-matchers'
gem 'factory_girl_rails'
gem 'faker'
gem 'capybara'
gem 'poltergeist'
gem 'simplecov'
end

View file

@ -35,6 +35,13 @@ GEM
sass (~> 3.2)
bootstrap_form (2.2.0)
builder (3.2.2)
capybara (2.4.3)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@ -85,12 +92,20 @@ GEM
mail (2.6.1)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_portile (0.6.0)
minitest (5.4.2)
multi_json (1.10.1)
mysql2 (0.3.16)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nprogress-rails (0.1.6.3)
orm_adapter (0.5.0)
pg (0.17.1)
poltergeist (1.5.1)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
@ -177,7 +192,10 @@ GEM
raindrops (~> 0.7)
warden (1.2.3)
rack (>= 1.0)
websocket-driver (0.4.0)
will_paginate (3.0.7)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
@ -187,6 +205,7 @@ DEPENDENCIES
bootstrap-material-design
bootstrap-sass (~> 3.2.0.1)
bootstrap_form
capybara
coffee-rails (~> 4.1.0)
devise
factory_girl_rails
@ -201,6 +220,7 @@ DEPENDENCIES
mysql2
nprogress-rails
pg
poltergeist
rails (= 4.1.7)
rspec-rails (~> 3.0.0)
sass-rails (~> 4.0.3)

View file

@ -21,7 +21,7 @@ Rails.application.configure do
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = true # was: false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

View file

@ -0,0 +1,23 @@
require 'rails_helper'
feature "User", :type => :feature do
before do
@user1 = create(:user)
@user2 = create(:user)
end
scenario "gets asked a question", js: true do
visit "/@#{@user1.screen_name}"
page.driver.render Rails.root.join("tmp/#{Time.now.to_i}.png"), full: true
fill_in "qb-question", with: Faker::Lorem.sentence
click_button "Ask"
wait_for_ajax
reload_page
page.driver.render Rails.root.join('tmp'), full: full
expect(page).to have_text("Question asked successfully.")
end
end

View file

@ -1,5 +1,4 @@
require 'rails_helper'
RSpec.describe User, :type => :model do
# TODO: specs for user model
end

View file

@ -1,14 +1,12 @@
require 'rails_helper'
RSpec.describe UserController, :type => :request do
RSpec.describe "user page", :type => :request do
before do
# we need at least 2 users to test meaningfully
@user1 = create(:user)
@user2 = create(:user)
@user = create(:user)
end
it 'shows the user page' do
get "/@#{@user1.screen_name}"
assert_select "h3.text-muted", :text => @user1.screen_name
get "/@#{@user.screen_name}"
assert_select "h3.text-muted", :text => @user.screen_name
end
end

View file

@ -1,6 +1,12 @@
require 'simplecov'
SimpleCov.start
# require 'capybara/rails'
# require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this

View file

@ -0,0 +1,15 @@
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
RSpec.configure do |config|
config.include WaitForAjax, type: :feature
end