-
Notifications
You must be signed in to change notification settings - Fork 20
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 rubocop #4524
Open
KludgeKML
wants to merge
20
commits into
main
Choose a base branch
from
rspec-rubocop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rspec rubocop #4524
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9238dbf
configure rubocop for rspec
KludgeKML cd6324a
run rubocop --autocorrect
KludgeKML 6dab178
Run rubocop -A
KludgeKML 54ad64c
Fix tests broken by rubocop -A
KludgeKML e8c538d
Fix lints in spec/components
KludgeKML d28abf6
lint: fix spec/helpers
KludgeKML e4517a5
lint: fix spec/models
KludgeKML b64750f
lint: fix spec/presenters
KludgeKML ef97c27
Convert method to matcher
KludgeKML c748cf7
lint: fix spec/requests
KludgeKML bf30659
lint: fix spec/requests added
KludgeKML fb14dd6
lint: fix spec/routing
KludgeKML 5cace6c
lint: fix spec/support
KludgeKML 25ad2a9
lint: fix spec/system
KludgeKML e4a8bf8
lint: fix spec/unit/presenters
KludgeKML d5a1904
lint: fix spec/unit/services
KludgeKML 7f7901d
lint: fix spec/unit/simple_smart_answers
KludgeKML 13895bb
lint: fix spec/unit/calendar
KludgeKML dd5e5d0
lint: fix spec/unit/sanitiser
KludgeKML eee8251
lint: fix spec/unit
KludgeKML File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,141 +1,137 @@ | ||
module SimpleSmartAnswers | ||
RSpec.describe Flow do | ||
context "finding nodes" do | ||
before do | ||
@nodes = [ | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-1", | ||
"title" => "Question 1", | ||
"body" => "<p>This is question 1</p>", | ||
"options" => [], | ||
}, | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-2", | ||
"title" => "Question 2", | ||
"body" => "<p>This is question 2</p>", | ||
"options" => [], | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
] | ||
@flow = described_class.new(@nodes) | ||
end | ||
RSpec.describe SimpleSmartAnswers::Flow do | ||
subject(:flow) { described_class.new(nodes) } | ||
|
||
it "returns the node matching the slug" do | ||
node = @flow.node_for_slug("question-2") | ||
context "when finding nodes" do | ||
let(:nodes) do | ||
[ | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-1", | ||
"title" => "Question 1", | ||
"body" => "<p>This is question 1</p>", | ||
"options" => [], | ||
}, | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-2", | ||
"title" => "Question 2", | ||
"body" => "<p>This is question 2</p>", | ||
"options" => [], | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
] | ||
end | ||
|
||
it "returns the node matching the slug" do | ||
node = flow.node_for_slug("question-2") | ||
|
||
expect(node).to be_a(Node) | ||
expect(node.title).to eq("Question 2") | ||
end | ||
expect(node).to be_a(SimpleSmartAnswers::Node) | ||
expect(node.title).to eq("Question 2") | ||
end | ||
|
||
it "returns nil if none match" do | ||
expect(@flow.node_for_slug("question-3")).to be_nil | ||
end | ||
it "returns nil if none match" do | ||
expect(flow.node_for_slug("question-3")).to be_nil | ||
end | ||
|
||
it "returns the first node as the start_node" do | ||
node = @flow.start_node | ||
it "returns the first node as the start_node" do | ||
node = flow.start_node | ||
|
||
expect(node).to be_a(Node) | ||
expect(node.title).to eq("Question 1") | ||
end | ||
expect(node).to be_a(SimpleSmartAnswers::Node) | ||
expect(node.title).to eq("Question 1") | ||
end | ||
end | ||
|
||
describe "#state_for_responses" do | ||
before do | ||
@flow = | ||
described_class.new( | ||
[ | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-1", | ||
"title" => "Question 1", | ||
"body" => "<p>This is question 1</p>", | ||
"options" => [ | ||
{ | ||
"label" => "Option 1", | ||
"slug" => "option-1", | ||
"next_node" => "question-2", | ||
}, | ||
{ | ||
"label" => "Option 2", | ||
"slug" => "option-2", | ||
"next_node" => "outcome-1", | ||
}, | ||
{ | ||
"label" => "Option 3", | ||
"slug" => "option-3", | ||
"next_node" => "outcome-2", | ||
}, | ||
], | ||
}, | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-2", | ||
"title" => "Question 2", | ||
"body" => "<p>This is question 2</p>", | ||
"options" => [ | ||
{ | ||
"label" => "Option 1", | ||
"slug" => "option-1", | ||
"next_node" => "outcome-1", | ||
}, | ||
{ | ||
"label" => "Option 2", | ||
"slug" => "option-2", | ||
"next_node" => "outcome-2", | ||
}, | ||
], | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-2", | ||
"title" => "Outcome 2", | ||
"body" => "<p>This is outcome 2</p>", | ||
}, | ||
], | ||
) | ||
end | ||
describe "#state_for_responses" do | ||
let(:nodes) do | ||
[ | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-1", | ||
"title" => "Question 1", | ||
"body" => "<p>This is question 1</p>", | ||
"options" => [ | ||
{ | ||
"label" => "Option 1", | ||
"slug" => "option-1", | ||
"next_node" => "question-2", | ||
}, | ||
{ | ||
"label" => "Option 2", | ||
"slug" => "option-2", | ||
"next_node" => "outcome-1", | ||
}, | ||
{ | ||
"label" => "Option 3", | ||
"slug" => "option-3", | ||
"next_node" => "outcome-2", | ||
}, | ||
], | ||
}, | ||
{ | ||
"kind" => "question", | ||
"slug" => "question-2", | ||
"title" => "Question 2", | ||
"body" => "<p>This is question 2</p>", | ||
"options" => [ | ||
{ | ||
"label" => "Option 1", | ||
"slug" => "option-1", | ||
"next_node" => "outcome-1", | ||
}, | ||
{ | ||
"label" => "Option 2", | ||
"slug" => "option-2", | ||
"next_node" => "outcome-2", | ||
}, | ||
], | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-1", | ||
"title" => "Outcome 1", | ||
"body" => "<p>This is outcome 1</p>", | ||
}, | ||
{ | ||
"kind" => "outcome", | ||
"slug" => "outcome-2", | ||
"title" => "Outcome 2", | ||
"body" => "<p>This is outcome 2</p>", | ||
}, | ||
] | ||
end | ||
|
||
it "returns a state for the given responses" do | ||
state = @flow.state_for_responses(%w[option-1]) | ||
it "returns a state for the given responses" do | ||
state = flow.state_for_responses(%w[option-1]) | ||
|
||
expect(state.current_node.slug).to eq("question-2") | ||
expect(state.current_question_number).to eq(2) | ||
expect(state.completed_questions.size).to eq(1) | ||
expect(state.current_node.slug).to eq("question-2") | ||
expect(state.current_question_number).to eq(2) | ||
expect(state.completed_questions.size).to eq(1) | ||
|
||
answer1 = state.completed_questions.first | ||
expect(answer1.label).to eq("Option 1") | ||
expect(answer1.slug).to eq("option-1") | ||
expect(answer1.question.title).to eq("Question 1") | ||
end | ||
answer1 = state.completed_questions.first | ||
expect(answer1.label).to eq("Option 1") | ||
expect(answer1.slug).to eq("option-1") | ||
expect(answer1.question.title).to eq("Question 1") | ||
end | ||
|
||
it "stops processing and set error flag on invalid response" do | ||
state = @flow.state_for_responses(%w[option-1 fooey option-2]) | ||
it "stops processing and set error flag on invalid response" do | ||
state = flow.state_for_responses(%w[option-1 fooey option-2]) | ||
|
||
expect(state.error?).to be true | ||
expect(state.current_node.slug).to eq("question-2") | ||
expect(state.current_question_number).to eq(2) | ||
expect(state.completed_questions.size).to eq(1) | ||
expect(state.completed_questions.first.slug).to eq("option-1") | ||
end | ||
expect(state.error?).to be true | ||
expect(state.current_node.slug).to eq("question-2") | ||
expect(state.current_question_number).to eq(2) | ||
expect(state.completed_questions.size).to eq(1) | ||
expect(state.completed_questions.first.slug).to eq("option-1") | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange that Outcome 1 is duplicated. Perhaps it can be deleted?