diff options
author | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-08-26 13:49:59 +0300 |
---|---|---|
committer | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-09-07 13:10:49 +0300 |
commit | bbba62fa51419b14be4f39873afdd45b5b248764 (patch) | |
tree | c10b2c727c4d392fb0956bb1d61b6cfe36b6eaff | |
parent | cfa18dab86d5408814f4c6083b843205c3d1599e (diff) |
Fix errors and grammar
-rw-r--r-- | lib/api/lint.rb | 23 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/lint_spec.rb | 17 |
3 files changed, 23 insertions, 25 deletions
diff --git a/lib/api/lint.rb b/lib/api/lint.rb index 2757b800af0..ff35e948e0c 100644 --- a/lib/api/lint.rb +++ b/lib/api/lint.rb @@ -9,23 +9,20 @@ module API post do response = { status: '', - errors: [], + error: [], jobs: [] } - if !Ci::GitlabCiYamlProcessor.errors(@content).nil? - status 200 - response[:errors].push(Ci::GitlabCiYamlProcessor.errors(@content)) - response[:status] = 'invalid' - - response - end + if Ci::GitlabCiYamlProcessor.errors(params[:content]).nil? + config_processor = Ci::GitlabCiYamlProcessor.new(params[:content]) - config_processor = Ci::GitlabCiYamlProcessor.new(params[:content]) - - config_processor.builds.each do |build| - response[:jobs].push("#{build[:name]}") - response[:status] = 'valid' + config_processor.builds.each do |build| + response[:jobs].push("#{build[:name]}") + response[:status] = 'valid' + end + else + response[:error].push(Ci::GitlabCiYamlProcessor.errors(params[:content])) + response[:status] = 'invalid' end status 200 diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 0125f149581..d3a37ba6eb5 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -1251,19 +1251,19 @@ EOT end end - describe "#errors(content)" do + describe "#errors" do describe "Error handling" do - it "returns error if parse YAML failed" do + it "returns an error if the YAML could not be parsed" do content = YAML.dump("invalid: yaml: test") expect(GitlabCiYamlProcessor.errors(content)).to eq "Invalid configuration format" end - it "returns errors if tags parameter is invalid" do + it "returns an error if the tags parameter is invalid" do content = YAML.dump({ rspec: { script: "test", tags: "mysql" } }) expect(GitlabCiYamlProcessor.errors(content)).to eq "jobs:rspec tags should be an array of strings" end - it "does not return errors" do + it "does not return any errors when the YAML is valid" do content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) expect(GitlabCiYamlProcessor.errors(content)).to eq nil end diff --git a/spec/requests/api/lint_spec.rb b/spec/requests/api/lint_spec.rb index 78a9b415405..8bad57819c8 100644 --- a/spec/requests/api/lint_spec.rb +++ b/spec/requests/api/lint_spec.rb @@ -9,7 +9,7 @@ describe API::API do describe 'POST /lint' do context 'with valid .gitlab-ci.yaml content' do - it 'validates content' do + it 'validates the content' do post api('/lint'), { content: yaml_content } expect(response).to have_http_status(200) @@ -18,29 +18,30 @@ describe API::API do end end - context 'with invalid .gitlab_ci.yml' do - it 'validates content and shows correct errors' do + context 'with an invalid .gitlab_ci.yml' do + it 'validates the content and shows an error message' do post api('/lint'), { content: 'invalid content' } expect(response).to have_http_status(200) expect(json_response['status']).to eq('invalid') - expect(json_response['errors']).to eq(['Invalid configuration format']) + expect(json_response['error']).to eq(['Invalid configuration format']) end - it "validates content and shows configuration error" do + it "validates the content and shows a configuration error" do post api('/lint'), { content: '{ image: "ruby:2.1", services: ["postgres"] }' } expect(response).to have_http_status(200) expect(json_response['status']).to eq('invalid') - expect(json_response['errors']).to eq(['jobs config should contain at least one visible job']) + expect(json_response['error']).to eq(['jobs config should contain at least one visible job']) end end - context 'no content parameters' do - it 'shows error message' do + context 'without the content parameter' do + it 'shows an error message' do post api('/lint') expect(response).to have_http_status(400) + expect(json_response['error']).to eq('content is missing') end end end |