Given /^the assessment timeout interval is set to (\d+) seconds$/ do |count| @original_assessment_timeout_interval = StudyEngine::Assessment.timeout_interval StudyEngine::Assessment.timeout_interval = count.to_i end After do if defined?(@original_assessment_timeout_interval) StudyEngine::Assessment.timeout_interval = @original_assessment_timeout_interval end end Given "the following study ids exist:" do |table| table.raw.each do |row| StudyEngine::StudyID::Bank.find_or_create_from_full_study_id row.first end end Given "the following assessment results exist:" do |table| table.hashes.each do |attributes| study_id = attributes["study_id"] baseline = attributes["baseline"] three_month = attributes["3 month"] six_month = attributes["6 month"] twelve_month = attributes["12 month"] create_stub_assessment study_id, "Baseline", baseline if baseline.present? create_stub_assessment study_id, "3 month", three_month if three_month.present? create_stub_assessment study_id, "6 month", six_month if six_month.present? create_stub_assessment study_id, "12 month", twelve_month if twelve_month.present? end end def create_stub_assessment study_id, event, time assessment = StudyEngine::Assessment.create!({ study_id: study_id, event: event, method_applied: "In-person", }) assessment.results.each do |result| result.update_attribute :finished, true end assessment.update({ created_at: time, assessment_updated_at: time, completed_at: time, }) assessment end When /^I choose "(.+?)" and "(.+?)" for the question pair$/ do |before, after| within all(".paired-bank")[0] do choose before end within all(".paired-bank")[1] do choose after end end When /^I should see the progress bar at (\d+%)$/ do |percent| begin find(".percentage", text: percent) rescue Capybara::ElementNotFound expect(find(".percentage").text).to eq(percent) end end Then 'I should see the "Start Assessment" form' do expect(page).to have_css("form input[value='Start Assessment']") end Then "I should see the following assessment results:" do |table| assessments = all(".results-table tr").map do |row| row.all("th,td").map(&:text) end table.diff! assessments end Then "I should see that notes are present" do find("label.note.-saved") end Then /^I should download a csv named "(.+?)" with the following contents:$/ do |filename, table| expect(page.response_headers['Content-Disposition']).to include("filename=\"#{filename}\"") page.execute_script """ window.xhrDownload = function(url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.send(null); return xhr.responseText; }; """ csv = page.evaluate_script("xhrDownload('#{@last_path}');") csv_table = CSV.parse(csv) table.diff! csv_table end