New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec #3

Merged
merged 2 commits into from Mar 27, 2016
Jump to file or symbol
Failed to load files and symbols.
+272 −79
Diff settings

Always

Just for now

View
2 .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
View
47 Gemfile
@@ -1,48 +1,29 @@
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta3', '< 5.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jbuilder', '~> 2.0'
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'puma'
gem 'rails', '>= 5.0.0.beta3', '< 5.1'
gem 'sass-rails', '~> 5.0'
gem 'sqlite3'
gem 'turbolinks', '~> 5.x'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'uglifier', '>= 1.3.0'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'capybara'
gem 'factory_girl_rails', "~> 4.0"
gem 'database_cleaner'
gem 'ffaker'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'web-console', '~> 3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
View
@@ -38,9 +38,19 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.4.0)
arel (7.0.0)
builder (3.2.2)
byebug (8.2.2)
capybara (2.6.2)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
@@ -49,18 +59,26 @@ GEM
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.1)
database_cleaner (1.5.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.6.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
ffaker (2.2.0)
ffi (1.9.10)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.4.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.1.0)
rails-dom-testing (~> 1.0)
jquery-rails (4.1.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
@@ -69,17 +87,19 @@ GEM
rb-inotify (>= 0.9.7)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (2.99.1)
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
nio4r (1.2.1)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
puma (3.0.2)
puma (3.2.0)
rack (2.0.0.alpha)
json
rack-test (0.6.3)
@@ -110,17 +130,38 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
rake (11.1.1)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rubyzip (1.2.0)
sass (3.4.21)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (2.53.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
spring (1.6.4)
spring-watcher-listen (2.0.0)
listen (>= 2.7, < 4.0)
@@ -138,32 +179,40 @@ GEM
tilt (2.0.2)
turbolinks (5.0.0.beta2)
turbolinks-source
turbolinks-source (5.0.0.beta2)
turbolinks-source (5.0.0.beta3)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
uglifier (3.0.0)
execjs (>= 0.3.0, < 3)
web-console (3.1.1)
activemodel (>= 4.2)
debug_inspector
railties (>= 4.2)
websocket (1.2.2)
websocket-driver (0.6.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
byebug
capybara
coffee-rails (~> 4.1.0)
database_cleaner
factory_girl_rails (~> 4.0)
ffaker
jbuilder (~> 2.0)
jquery-rails
listen (~> 3.0.5)
puma
rails (>= 5.0.0.beta3, < 5.1)
rspec-rails
sass-rails (~> 5.0)
selenium-webdriver
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
View
@@ -1,4 +1,6 @@
class Student < ApplicationRecord
validates :name, presence: true
def self.majors
records = Student.select(:major).distinct
records.map(&:major)
View
@@ -0,0 +1,19 @@
require 'ffaker'
FactoryGirl.define do
factory :student do
name { FFaker::Name.name }
gpa 3.5
major { FFaker::Education.major }
trait :non_cs do
name "Mary"
major "English"
end
trait :cs do
name "Lynn"
major "CS"
end
end
end
@@ -0,0 +1,48 @@
require 'rails_helper'
describe "the index page", :type => :feature do
before do
10.times do
create(:student)
end
create(:student, :cs)
create(:student, :non_cs)
visit "/"
end
it "displays a list of students" do
expect(page).to have_content('Students at University')
expect(page).to have_content('Mary')
expect(page).to have_content('Lynn')
expect(find_field("major-select").value).to eq "Filter by major:"
end
it "filters by major" do
select('CS', from: "major-select")
visit(root_path + "/?major=CS")
expect(page).to_not have_content('Mary')
expect(page).to have_content('Lynn')
end
end
describe "Selenium run" do
before(:each) do
@driver = Selenium::WebDriver.for :chrome
@base_url = "localhost:3000"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
end
after(:each) do
@driver.quit
end
it "persists the chosen select box option" do
skip
@driver.get(@base_url + "/?major=CS")
# no value is showing up in drop-down with Selenium, I think it's bc it populates
# from a cookie. I should change that to populate from the major parameter in the url.
# @driver.save_screenshot('screenshot.png')
expect(@driver.execute_script("return $('#major-select').val()")).to eq "CS"
end
end
@@ -0,0 +1,9 @@
describe Student do
it 'has a valid factory' do
expect(build(:student)).to be_valid
end
it 'is invalid without a name' do
expect(build(:student, name: nil)).to_not be_valid
end
end
View
@@ -0,0 +1,33 @@
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require "selenium-webdriver"
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.include FactoryGirl::Syntax::Methods
config.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
config.include Rails.application.routes.url_helpers
config.include Capybara::DSL
end
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.