Merge pull request #160 from openHPI/SS/enable_more_specs

Enable more specs
This commit is contained in:
rteusner
2018-03-22 15:10:35 +01:00
committed by GitHub
10 changed files with 95 additions and 81 deletions

View File

@ -8,6 +8,7 @@ addons:
repo_token:
secure: "cZoMNjQKB/D7W4B7JDk9PXooy2WCDypu7R4C/Vi0DziZCU9HRwLbdt9aoH5hgHFa7Fe2rHFgflPAAP7h698ozvP0waFtPqLAj+PbEt27LbBDvW8JcvNkKXA0rj5wyTkzuc/0kD+kPB4oDXMak6gZlB9HCJDsa3kdXScQGTVuPdU="
postgresql: "9.6"
firefox: "latest"
before_install:
- export DISPLAY=:99.0
@ -17,6 +18,12 @@ before_install:
- sleep 5
- docker pull openhpi/co_execenv_python
- docker pull openhpi/co_execenv_java
- mkdir ~/geckodriver
- wget -O ~/geckodriver/download.tar.gz https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz
- tar -xvzf ~/geckodriver/download.tar.gz -C ~/geckodriver/
- rm ~/geckodriver/download.tar.gz
- chmod +x ~/geckodriver/geckodriver
- export PATH=~/geckodriver/:$PATH
before_script:
- cp .rspec.travis .rspec

View File

@ -67,12 +67,13 @@ end
group :test do
gem 'autotest-rails'
gem 'capybara'
gem 'capybara-selenium'
gem 'headless'
gem 'codeclimate-test-reporter', require: false
gem 'database_cleaner'
gem 'nyan-cat-formatter'
gem 'rake'
gem 'rspec-autotest'
gem 'rspec-rails'
gem 'selenium-webdriver'
gem 'simplecov', require: false
end

View File

@ -85,6 +85,9 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
capybara-selenium (0.0.6)
capybara
selenium-webdriver
carrierwave (1.2.2)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
@ -136,6 +139,7 @@ GEM
forgery (0.7.0)
globalid (0.4.1)
activesupport (>= 4.2.0)
headless (2.3.1)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
@ -383,6 +387,7 @@ DEPENDENCIES
capistrano-upload-config
capistrano3-puma
capybara
capybara-selenium
carrierwave
codeclimate-test-reporter
coffee-rails
@ -395,6 +400,7 @@ DEPENDENCIES
factory_bot_rails
faye-websocket
forgery
headless
highline
ims-lti (= 1.1.10)
jbuilder
@ -423,7 +429,6 @@ DEPENDENCIES
rubyzip
sass-rails
sdoc
selenium-webdriver
simplecov
slim
sorcery

View File

View File

@ -1,7 +1,7 @@
require 'rails_helper'
describe 'Editor', js: true do
let(:exercise) { FactoryBot.create(:audio_video, instructions: Forgery(:lorem_ipsum).sentence) }
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
let(:user) { FactoryBot.create(:teacher) }
before(:each) do
@ -9,94 +9,74 @@ describe 'Editor', js: true do
fill_in('email', with: user.email)
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
click_button(I18n.t('sessions.new.link'))
expect_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true)
visit(implement_exercise_path(exercise))
end
skip "is skipped" do
# selenium tests are currently not working locally.
it 'displays the exercise title' do
expect(page).to have_content(exercise.title)
it 'displays the exercise title' do
expect(page).to have_content(exercise.title)
end
it 'displays the exercise description' do
expect(page).to have_content(exercise.description)
end
it 'displays all visible files in a file tree' do
within('#files') do
exercise.files.select(&:visible).each do |file|
expect(page).to have_content(file.name_with_extension)
end
end
end
describe 'Instructions Tab' do
skip "is skipped" do
it "displays the main file's code" do
expect(page).to have_css(".frame[data-filename='#{exercise.files.detect(&:main_file?).name_with_extension}']")
end
before(:each) { click_link(I18n.t('activerecord.attributes.exercise.instructions')) }
it 'displays the exercise instructions' do
expect(page).to have_content(exercise.instructions)
context 'when selecting a file' do
before(:each) do
within('#files') { click_link(file.name_with_extension) }
end
context 'when selecting a binary file' do
context 'when selecting an audio file' do
let(:file) { exercise.files.detect { |file| file.file_type.audio? } }
it 'contains an <audio> tag' do
expect(page).to have_css("audio[src='#{file.native_file.url}']")
end
end
context 'when selecting an image file' do
let(:file) { exercise.files.detect { |file| file.file_type.image? } }
it 'contains an <img> tag' do
expect(page).to have_css("img[src='#{file.native_file.url}']")
end
end
context 'when selecting a video file' do
let(:file) { exercise.files.detect { |file| file.file_type.video? } }
it 'contains a <video> tag' do
expect(page).to have_css("video[src='#{file.native_file.url}']")
end
end
end
context 'when selecting a non-binary file' do
let(:file) { exercise.files.detect { |file| !file.file_type.binary? && !file.hidden? } }
it "displays the file's code" do
expect(page).to have_css(".frame[data-filename='#{file.name_with_extension}']")
end
end
end
describe 'Workspace Tab' do
skip "is skipped" do
before(:each) { click_link(I18n.t('exercises.implement.workspace')) }
it 'displays all visible files in a file tree' do
within('#files') do
exercise.files.select(&:visible).each do |file|
expect(page).to have_content(file.name_with_extension)
end
end
end
it "displays the main file's code" do
expect(page).to have_css(".frame[data-filename='#{exercise.files.detect(&:main_file?).name_with_extension}']")
end
context 'when selecting a file' do
before(:each) do
within('#files') { click_link(file.name_with_extension) }
end
context 'when selecting a binary file' do
context 'when selecting an audio file' do
let(:file) { exercise.files.detect { |file| file.file_type.audio? } }
it 'contains an <audio> tag' do
expect(page).to have_css("audio[src='#{file.native_file.url}']")
end
end
context 'when selecting an image file' do
let(:file) { exercise.files.detect { |file| file.file_type.image? } }
it 'contains an <img> tag' do
expect(page).to have_css("img[src='#{file.native_file.url}']")
end
end
context 'when selecting a video file' do
let(:file) { exercise.files.detect { |file| file.file_type.video? } }
it 'contains a <video> tag' do
expect(page).to have_css("video[src='#{file.native_file.url}']")
end
end
end
context 'when selecting a non-binary file' do
let(:file) { exercise.files.detect { |file| !file.file_type.binary? } }
it "displays the file's code" do
expect(page).to have_css(".frame[data-filename='#{file.name_with_extension}']")
end
end
end
end
end
describe 'Progress Tab' do
skip "is skipped" do
before(:each) { click_link(I18n.t('exercises.implement.progress')) }
it 'does not contains a button for submitting the exercise' do
# pending("the button is only displayed when an correct LTI handshake to a running course happened. This is not the case in the test")
expect(page).not_to have_css('#submit')
end
end
it 'does not contains a button for submitting the exercise' do
click_button(I18n.t('exercises.editor.score'))
click_button('toggle-sidebar-output-collapsed')
expect(page).not_to have_css('#submit_outdated')
expect(page).to have_css('#submit')
end
end

21
spec/support/selenium.rb Normal file
View File

@ -0,0 +1,21 @@
require 'capybara/rspec'
require 'selenium/webdriver'
if ENV['HEADLESS_TEST'] == 'true' || ENV['USER'] == 'vagrant'
require 'headless'
headless = Headless.new
headless.start
end
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile['intl.accept_languages'] = 'en'
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(elementScrollBehavior: 1)
options = Selenium::WebDriver::Firefox::Options.new
options.profile = profile
driver = Capybara::Selenium::Driver.new(app, browser: :firefox, desired_capabilities: capabilities, options: options)
driver.browser.manage.window.resize_to(1280, 960)
driver
end
Capybara.javascript_driver = :selenium

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB