Skip to content

Commit

Permalink
providing suggestion for unimplemented step getgauge/gauge-vscode#85 #47
Browse files Browse the repository at this point in the history
  • Loading branch information
BugDiver committed Jan 12, 2018
1 parent 1407034 commit 5db3a5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
17 changes: 13 additions & 4 deletions lib/processors/step_validation_request_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,30 @@ module Processors
def process_step_validation_request(message)
step_validate_request = message.stepValidateRequest
is_valid = true
msg = ''
msg,suggestion = ''
err_type = nil
if !MethodCache.valid_step? step_validate_request.stepText
is_valid = false
msg = 'Step implementation not found'
err_type = Messages::StepValidateResponse::ErrorType::STEP_IMPLEMENTATION_NOT_FOUND
suggestion = create_suggestion step_validate_request.stepValue
elsif MethodCache.multiple_implementation?(step_validate_request.stepText)
is_valid = false
msg = "Multiple step implementations found for => '#{step_validate_request.stepText}'"
err_type = Messages::StepValidateResponse::ErrorType::DUPLICATE_STEP_IMPLEMENTATION
suggestion = ''
end
step_validate_response = Messages::StepValidateResponse.new(:isValid => is_valid, :errorMessage => msg, :errorType => err_type)
step_validate_response = Messages::StepValidateResponse.new(:isValid => is_valid, :errorMessage => msg, :errorType => err_type, :suggestion => suggestion)
Messages::Message.new(:messageType => Messages::Message::MessageType::StepValidateResponse,
:messageId => message.messageId,
:stepValidateResponse => step_validate_response)
:messageId => message.messageId,
:stepValidateResponse => step_validate_response)
end

def create_suggestion(step_value)
count = -1
step_text = step_value.stepValue.gsub(/{}/) {"<arg#{count += 1}>"}
params = step_value.parameters.map.with_index {|v,i| "arg#{i}"}.join ", "
"step '#{step_text}' do |#{params}|\n\traise 'Unimplemented Step';\nend"
end
end
end
15 changes: 10 additions & 5 deletions spec/validate_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.

describe Gauge::Processors do
let(:given_block) { -> { puts 'foo' } }
let(:given_block) {-> {puts 'foo'}}
let(:message) {double('message')}
context '.process_step_validation_request' do
describe 'should return valid response' do
before {
Gauge::MethodCache.add_step 'step_text1', {block: given_block}
allow(message).to receive_message_chain(:stepValidateRequest, :stepText => 'step_text1')
allow(message).to receive(:messageId) { 1 }
allow(message).to receive(:messageId) {1}
}
it 'should get registered <block>' do
expect(subject.process_step_validation_request(message).stepValidateResponse.isValid).to eq true
Expand All @@ -35,7 +35,7 @@
Gauge::MethodCache.add_step 'step_text2', {block: given_block}
Gauge::MethodCache.add_step 'step_text2', {block: given_block}
allow(message).to receive_message_chain(:stepValidateRequest, :stepText => 'step_text2')
allow(message).to receive(:messageId) { 1 }
allow(message).to receive(:messageId) {1}
}
it {
response = subject.process_step_validation_request(message).stepValidateResponse
Expand All @@ -46,13 +46,18 @@

describe 'should return error response when no step impl' do
before {
allow(message).to receive_message_chain(:stepValidateRequest, :stepText => 'step_text3')
allow(message).to receive(:messageId) { 1 }
allow(message).to receive_message_chain(:stepValidateRequest, :stepValue, :stepValue => 'step_text3 {}')
allow(message).to receive_message_chain(:stepValidateRequest, :stepValue, :parameterizedStepValue => 'step_text3 <hello>')
allow(message).to receive_message_chain(:stepValidateRequest, :stepValue, :parameters => ['hello'])
allow(message).to receive_message_chain(:stepValidateRequest, :stepText, 'step_text3 {}')
allow(message).to receive(:messageId) {1}
}
it {
expected_suggestion = "step 'step_text3 <arg0>' do |arg0|\n\traise 'Unimplemented Step';\nend"
response = subject.process_step_validation_request(message).stepValidateResponse
expect(response.isValid).to eq false
expect(response.errorMessage).to eq 'Step implementation not found'
expect(response.suggestion).to eq expected_suggestion
}
end
end
Expand Down

0 comments on commit 5db3a5c

Please sign in to comment.