rainforest-cli 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+ module RainforestCli::TestParser
2
+ class EmbeddedTest < Struct.new(:test_name)
3
+ def to_s
4
+ "--> embed: #{test_name}"
5
+ end
6
+ end
7
+
8
+ class Step < Struct.new(:action, :response)
9
+ def to_s
10
+ "#{action} --> #{response}"
11
+ end
12
+ end
13
+
14
+ class Error < Struct.new(:line, :reason)
15
+ def to_s
16
+ "Line #{line}: #{reason}"
17
+ end
18
+ end
19
+
20
+ class Test < Struct.new(:id, :description, :title, :start_uri, :steps, :errors, :tags, :browsers)
21
+ end
22
+
23
+ class Parser
24
+ attr_reader :steps, :errors, :text
25
+
26
+ def initialize(text)
27
+ @text = text.to_s
28
+
29
+ @test = Test.new
30
+ @test.description = ""
31
+ @test.steps = []
32
+ @test.errors = {}
33
+ @test.tags = []
34
+ @test.browsers = []
35
+ end
36
+
37
+ TEXT_FIELDS = [:start_uri, :title, :tags].freeze
38
+ CSV_FIELDS = [:tags, :browsers].freeze
39
+
40
+ def process
41
+ scratch = []
42
+
43
+ text.lines.map(&:chomp).each_with_index do |line, line_no|
44
+ if line[0..1] == '#!'
45
+ # special comment, don't ignore!
46
+ @test.id = line[2..-1].strip.split(" ")[0]
47
+ @test.description += line[1..-1] + "\n"
48
+
49
+ elsif line[0] == '#'
50
+ # comment, store in description
51
+ @test.description += line[1..-1] + "\n"
52
+
53
+ (CSV_FIELDS + TEXT_FIELDS).each do |field|
54
+ next unless line[1..-1].strip[0..(field.length)] == "#{field}:"
55
+
56
+ # extract just the text of the field
57
+ @test[field] = line[1..-1].split(" ")[1..-1].join(" ").strip
58
+
59
+ # if it's supposed to be a CSV field, split and trim it
60
+ if CSV_FIELDS.include?(field)
61
+ @test[field] = @test[field].split(',').map(&:strip).map(&:downcase)
62
+ end
63
+ end
64
+
65
+ elsif scratch.count == 0 && line.strip != ''
66
+ if line[0] == '-'
67
+ @test.steps << EmbeddedTest.new(line[1..-1].strip)
68
+ else
69
+ scratch << line.strip
70
+ end
71
+
72
+ elsif scratch.count == 1
73
+ if line.strip == ''
74
+ @test.errors[line_no] = Error.new(line_no, "Missing question")
75
+ elsif !line.include?('?')
76
+ @test.errors[line_no] = Error.new(line_no, "Missing ?")
77
+ else
78
+ scratch << line.strip
79
+ end
80
+
81
+ end
82
+
83
+ if @test.errors.has_key?(line_no)
84
+ scratch = []
85
+ end
86
+
87
+ if scratch.count == 2
88
+ @test.steps << Step.new(scratch[0], scratch[1])
89
+ scratch = []
90
+ end
91
+ end
92
+
93
+ if @test.id == nil
94
+ @test.errors[0] = Error.new(0, "Missing test ID. Please start a line #! followed by a unique id.")
95
+ end
96
+
97
+ return @test
98
+ end
99
+ end
100
+ end
@@ -1,5 +1,3 @@
1
- module Rainforest
2
- module Cli
3
- VERSION = "1.0.6"
4
- end
1
+ module RainforestCli
2
+ VERSION = "1.1.0"
5
3
  end
@@ -5,7 +5,7 @@ require 'rainforest/cli/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rainforest-cli"
8
- spec.version = Rainforest::Cli::VERSION
8
+ spec.version = RainforestCli::VERSION
9
9
  spec.authors = ["Simon Mathieu", "Russell Smith"]
10
10
  spec.email = ["simon@rainforestqa.com", "russ@rainforestqa.com"]
11
11
  spec.description = %q{Command line utility for Rainforest QA}
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "httparty"
22
22
  spec.add_dependency "parallel"
23
23
  spec.add_dependency "ruby-progressbar"
24
+ spec.add_dependency "rainforest"
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
26
27
  end
data/spec/cli_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
- describe Rainforest::Cli do
2
- let(:http_client) { Rainforest::Cli::HttpClient.any_instance }
1
+ describe RainforestCli do
2
+ let(:http_client) { RainforestCli::HttpClient.any_instance }
3
3
 
4
4
  before do
5
5
  Kernel.stub(:sleep)
@@ -52,7 +52,7 @@ describe Rainforest::Cli do
52
52
  end
53
53
 
54
54
  before do
55
- Rainforest::Cli::GitTrigger.stub(:last_commit_message) { commit_message }
55
+ RainforestCli::GitTrigger.stub(:last_commit_message) { commit_message }
56
56
  end
57
57
 
58
58
  describe "with tags parameter passed" do
@@ -134,7 +134,7 @@ describe Rainforest::Cli do
134
134
  end
135
135
 
136
136
  it "starts the run with site_id and environment_id" do
137
- Rainforest::Cli::Runner.any_instance.stub(get_environment_id: 333)
137
+ RainforestCli::Runner.any_instance.stub(get_environment_id: 333)
138
138
 
139
139
  http_client.should_receive(:post).with(
140
140
  "/runs",
@@ -148,7 +148,7 @@ describe Rainforest::Cli do
148
148
  let(:params) { %w(--token x --environment 123) }
149
149
 
150
150
  it "starts the run with environment_id" do
151
- Rainforest::Cli::Runner.any_instance.stub(get_environment_id: 333)
151
+ RainforestCli::Runner.any_instance.stub(get_environment_id: 333)
152
152
 
153
153
  http_client.should_receive(:post).with(
154
154
  "/runs",
@@ -1,4 +1,4 @@
1
- describe Rainforest::Cli::CSVImporter do
1
+ describe RainforestCli::CSVImporter do
2
2
  let(:csv_file) { "#{File.dirname(__FILE__)}/fixtures/variables.txt" }
3
3
 
4
4
  describe '.import' do
@@ -15,7 +15,7 @@ describe Rainforest::Cli::CSVImporter do
15
15
  end
16
16
 
17
17
  before do
18
- Rainforest::Cli::HttpClient.stub(:new).and_return(http_client)
18
+ RainforestCli::HttpClient.stub(:new).and_return(http_client)
19
19
  end
20
20
 
21
21
  it 'should post the schema to the generators API' do
@@ -1,4 +1,4 @@
1
- describe Rainforest::Cli::GitTrigger do
1
+ describe RainforestCli::GitTrigger do
2
2
  subject { described_class }
3
3
 
4
4
  let(:default_dir) { __dir__ }
data/spec/options_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
- describe Rainforest::Cli::OptionParser do
2
- subject { Rainforest::Cli::OptionParser.new(args) }
1
+ describe RainforestCli::OptionParser do
2
+ subject { RainforestCli::OptionParser.new(args) }
3
3
 
4
4
  describe "#initialize" do
5
5
  context "importing csv file" do
@@ -38,7 +38,7 @@ describe Rainforest::Cli::OptionParser do
38
38
  let(:args) { ["run", "--browsers", "lulbrower"] }
39
39
 
40
40
  it "raises an exception" do
41
- expect{subject}.to raise_error(Rainforest::Cli::BrowserException)
41
+ expect{subject}.to raise_error(RainforestCli::BrowserException)
42
42
  end
43
43
  end
44
44
 
@@ -65,8 +65,15 @@ describe Rainforest::Cli::OptionParser do
65
65
  end
66
66
 
67
67
  context "it parses the conflict flag" do
68
- let(:args) { ["run", "--conflict", "abort", "all"] }
69
- its(:conflict) { should == "abort"}
68
+ context "when abort" do
69
+ let(:args) { ["run", "--conflict", "abort", "all"] }
70
+ its(:conflict) { should == "abort"}
71
+ end
72
+
73
+ context "when abort-all" do
74
+ let(:args) { ["run", "--conflict", "abort-all", "all"]}
75
+ its(:conflict) { should == "abort-all" }
76
+ end
70
77
  end
71
78
 
72
79
  context "it parses the fail-fast flag" do
data/spec/runner_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
- describe Rainforest::Cli::Runner do
1
+ describe RainforestCli::Runner do
2
2
  let(:args) { %w(run all) }
3
- let(:options) { Rainforest::Cli::OptionParser.new(args) }
3
+ let(:options) { RainforestCli::OptionParser.new(args) }
4
4
  subject { described_class.new(options) }
5
5
 
6
6
  describe "#get_environment_id" do
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  require "rainforest/cli"
9
9
 
10
- Rainforest::Cli.logger = Logger.new(StringIO.new)
10
+ RainforestCli.logger = Logger.new(StringIO.new)
11
11
 
12
12
  RSpec.configure do |config|
13
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainforest-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-11 00:00:00.000000000 Z
12
+ date: 2016-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rainforest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: bundler
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,8 @@ files:
108
122
  - lib/rainforest/cli/http_client.rb
109
123
  - lib/rainforest/cli/options.rb
110
124
  - lib/rainforest/cli/runner.rb
125
+ - lib/rainforest/cli/test_importer.rb
126
+ - lib/rainforest/cli/test_parser.rb
111
127
  - lib/rainforest/cli/version.rb
112
128
  - rainforest-cli.gemspec
113
129
  - spec/cli_spec.rb
@@ -137,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
153
  version: '0'
138
154
  requirements: []
139
155
  rubyforge_project:
140
- rubygems_version: 2.4.6
156
+ rubygems_version: 2.5.1
141
157
  signing_key:
142
158
  specification_version: 4
143
159
  summary: Command line utility for Rainforest QA