Skip to content

Commit

Permalink
Merge pull request #13 from tamu-edu-students/adding-cucumber-tests
Browse files Browse the repository at this point in the history
Adding cucumber tests
  • Loading branch information
jacobtoddmathes authored Feb 16, 2024
2 parents 45a15bf + a940146 commit 909a34a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rails_root/features/analysis_result_presentation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Present Analysis Results
Present the results of the leadership survey

Scenario: Invalid survey inputs
Given I have completed the survey with invalid inputs
When I try to submit the form
Then I do not get redirected to the analysis presentation page

Scenario: Valid survey inputs
Given I have completed the survey with valid inputs
When I try to submit the form
Then I do get redirected to the analysis presentation page
12 changes: 12 additions & 0 deletions rails_root/features/data_model_design.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Establish Project Data Models
Verify the correctness of the data models

Scenario: Invalid model attributes
Given I have a set of invalid attributes
When I try to create model instances
Then the model was not created

Scenario: Valid model attributes
Given I have a set of valid attributes
When I try to create model instances
Then the model was created
73 changes: 73 additions & 0 deletions rails_root/features/step_definitions/stepdefs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Analysis Result Presentation Steps
Given('I have completed the survey with invalid inputs') do
@attributes = {}
SurveyResponse.column_names.each do |name|
@attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at'
end
end

Given('I have completed the survey with valid inputs') do
@attributes = {}
SurveyResponse.column_names.each do |name|
@attributes[name] = 1 if name != 'id' && name != 'created_at' && name != 'updated_at'
end
end

When('I try to submit the form') do
visit new_survey_response_path
@attributes.each do |key, value|
fill_in 'survey_response_' + key.to_s, with: value
end
click_button 'commit'
end

Then('I do not get redirected to the analysis presentation page') do
expect(page).not_to have_content('Survey response was successfully created')
end

Then('I do get redirected to the analysis presentation page') do
expect(page).to have_current_path(survey_response_url(SurveyResponse.last))
expect(page).to have_content('Survey response was successfully created')
end

# Data Model Design Steps
Given('I have a set of invalid attributes') do
@survey_profiles_attributes = {}
SurveyProfile.column_names.each do |name|
@survey_profiles_attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at'
end
@survey_responses_attributes = {}
SurveyResponse.column_names.each do |name|
@survey_responses_attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at'
end
end

When('I try to create model instances') do
p @survey_profiles_attributes
p @survey_responses_attributes
SurveyProfile.create(@survey_profiles_attributes)
SurveyResponse.create(@survey_responses_attributes)
end

Given('I have a set of valid attributes') do
@survey_profiles_attributes = {}
SurveyProfile.column_names.each do |name|
@survey_profiles_attributes[name] = 10 if name != 'id' && name != 'created_at' && name != 'updated_at'
end
@survey_responses_attributes = {}
SurveyResponse.column_names.each do |name|
@survey_responses_attributes[name] = 10 if name != 'id' && name != 'created_at' && name != 'updated_at'
end
end

Then('the model was not created') do
expect(SurveyProfile.last.user_id).not_to be_nil
expect(SurveyResponse.last.user_id).not_to be_nil
end

Then('the model was created') do
p SurveyProfile.last
p SurveyResponse.last
expect(SurveyProfile.last.user_id).to eq(10)
expect(SurveyResponse.last.user_id).to eq(10)
end

0 comments on commit 909a34a

Please sign in to comment.