behave 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rest-client'
4
+ gem 'rubyzip'
5
+
6
+ # Specify your gem's dependencies in behave.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ behave (0.1)
5
+ rest-client
6
+ rubyzip
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.1.3)
12
+ mime-types (1.19)
13
+ rest-client (1.6.7)
14
+ mime-types (>= 1.16)
15
+ rspec (2.11.0)
16
+ rspec-core (~> 2.11.0)
17
+ rspec-expectations (~> 2.11.0)
18
+ rspec-mocks (~> 2.11.0)
19
+ rspec-core (2.11.1)
20
+ rspec-expectations (2.11.3)
21
+ diff-lcs (~> 1.1.3)
22
+ rspec-mocks (2.11.3)
23
+ rubyzip (0.9.9)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ behave!
30
+ rest-client
31
+ rspec (~> 2.6)
32
+ rubyzip
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jack Bastow
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Behave
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'behave'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install behave
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/behave.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'behave/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+
8
+ gem.add_development_dependency "rspec", "~> 2.6"
9
+
10
+ gem.add_dependency "rest-client"
11
+ gem.add_dependency "rubyzip"
12
+
13
+ gem.name = "behave"
14
+ gem.version = Behave::VERSION
15
+ gem.authors = ["Jack Bastow"]
16
+ gem.email = ["jack.bastow@hindsightsoftware.co.uk"]
17
+ gem.description = "Behave for Jira CLI"
18
+ gem.summary = "Command Line Interface for fetching features and scenarios from the Jira server"
19
+ gem.homepage = "http://www.hindsighttesting.com"
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+ end
data/bin/behave-cli ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'behave'
3
+
4
+ Behave::CLI.new(ARGV)
data/lib/behave.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'zip/zip'
4
+ require 'optparse'
5
+ require 'optparse/time'
6
+ require 'ostruct'
7
+ require 'pp'
8
+
9
+ module Behave
10
+
11
+ class FeatureDownloader
12
+ attr_accessor :host, :user, :pass, :key, :dir, :manual, :contents
13
+
14
+ def initialize(args)
15
+ @dir = "./"
16
+ @manual = false
17
+ args.each do |k,v|
18
+ instance_variable_set("@#{k}", v) unless v.nil? or k == 'contents'
19
+ end
20
+ if @host.nil? or key.nil?
21
+ puts '--------------------------------------------------------------'
22
+ puts 'Must set at least Jira host URI and project key'
23
+ puts 'if running from command line, use "behave-cli --help"'
24
+ puts '--------------------------------------------------------------'
25
+ exit 1
26
+ end
27
+ @key.upcase!
28
+ @dir << '/' unless @dir[-1,1] == '/'
29
+ @host << '/' unless @host[-1,1] == '/'
30
+ output_vars()
31
+ fetch()
32
+ extract()
33
+ end
34
+
35
+ def output_vars()
36
+ puts '--------------------------------------------------------------'
37
+ puts 'HOST: ' + @host
38
+ puts 'PROJECT KEY: ' + @key
39
+ puts 'USER: ' + @user
40
+ puts 'DIRECTORY: ' + @dir
41
+ puts 'INCLUDE MANUAL: ' + @manual.to_s
42
+ end
43
+
44
+ def fetch()
45
+ path = @host + 'rest/cucumber/1.0/project/' + @key + '/features'
46
+ if @user.nil? then
47
+ response = RestClient::Resource.new(path, :content_type => 'application/zip')
48
+ else
49
+ response = RestClient::Resource.new(path, :user => @user, :password => @pass, :content_type => 'application/zip')
50
+ end
51
+
52
+ begin
53
+ @contents = response.get(:accept => 'application/zip', :params => {:manual => @manual})
54
+ puts '--------------------------------------------------------------'
55
+ puts 'Fetched file from server...'
56
+ rescue => e
57
+ puts '--------------------------------------------------------------'
58
+ case e.response.code
59
+ when 401
60
+ puts 'User unauthorized (401)'
61
+ when 406
62
+ puts 'Behave running on server is outdated, cannot download features'
63
+ puts 'Please upgrade your version of Behave for Jira and try again'
64
+ when 500
65
+ puts 'Jira server error (500)'
66
+ end
67
+ puts 'Writing server response to error.log...'
68
+ File.open('error.log', 'w') {|f| f.write(e.response) }
69
+ puts 'ABORTING'
70
+ puts '--------------------------------------------------------------'
71
+ exit 1
72
+ end
73
+ end
74
+
75
+ def extract()
76
+ return if @contents.nil?
77
+ count = 0
78
+ Dir.mkdir(@dir) unless File.exists?(@dir)
79
+ File.open(@dir + 'features.zip', 'w') {|f| f.write(@contents) }
80
+ Zip::ZipFile::foreach("#{@dir}features.zip") {|feature|
81
+ path = @dir + feature.to_s
82
+ File.delete(path) if File.exists?(path)
83
+ feature.extract(path)
84
+ count += 1
85
+ }
86
+ File.delete(@dir + 'features.zip')
87
+ puts '--------------------------------------------------------------'
88
+ puts 'Successfully extracted ' + count.to_s + ' feature(s)'
89
+ puts '--------------------------------------------------------------'
90
+ exit 0
91
+ end
92
+
93
+ end
94
+
95
+ class CLI
96
+ attr_accessor :fd
97
+
98
+ def initialize(args)
99
+ attrs = parse(args)
100
+ @fd = Behave::FeatureDownloader.new(attrs)
101
+ end
102
+
103
+ def parse(args)
104
+ map = {}
105
+ map["dir"] = "./"
106
+
107
+ opts = OptionParser.new do |opts|
108
+ opts.banner = "Usage: behave [options]"
109
+
110
+ opts.separator ""
111
+ opts.separator "Specific options:"
112
+
113
+ opts.on("-h", "--host HOST",
114
+ "Host URI for Jira installation") do |host|
115
+ host << '/' unless host[-1,1] == '/'
116
+ map["host"] = host
117
+ end
118
+
119
+ opts.on("-u", "--user USER",
120
+ "User with Behave rights on project") do |user|
121
+ map["user"] = user
122
+ end
123
+
124
+ opts.on("-p", "--pass PASS",
125
+ "Password of user") do |pass|
126
+ map["pass"] = pass
127
+ end
128
+
129
+ opts.on("-k", "--key KEY",
130
+ "Project key to download features from") do |key|
131
+ map["key"] = key
132
+ end
133
+
134
+ opts.on("-d", "--directory [DIR]",
135
+ "Specify output directory (default './')") do |dir|
136
+ dir << '/' unless dir[-1,1] == '/'
137
+ map["dir"] = dir
138
+ end
139
+
140
+ opts.on("-m", "--manual",
141
+ "Include manual tagged scenarios in download") do
142
+ map["manual"] = true
143
+ end
144
+
145
+ opts.on_tail("--help", "Show this message") do
146
+ puts opts
147
+ exit
148
+ end
149
+
150
+ opts.on_tail("--version", "Show version") do
151
+ puts Behave::VERSION
152
+ exit
153
+ end
154
+ end
155
+
156
+ opts.parse!(args)
157
+
158
+ return map
159
+
160
+ end
161
+ end
162
+
163
+ end
@@ -0,0 +1,3 @@
1
+ module Behave
2
+ VERSION = "0.1"
3
+ end
Binary file
@@ -0,0 +1,5 @@
1
+ #Generated by Maven
2
+ #Mon Oct 15 16:52:00 BST 2012
3
+ version=1.0.0-BETA7-SNAPSHOT
4
+ groupId=com.hindsighttesting.behave
5
+ artifactId=rubycli
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: behave
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Jack Bastow
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-10-17 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.6"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rest-client
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rubyzip
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: Behave for Jira CLI
49
+ email:
50
+ - jack.bastow@hindsightsoftware.co.uk
51
+ executables:
52
+ - behave-cli
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE.txt
62
+ - README.md
63
+ - Rakefile
64
+ - behave-0.1.gem
65
+ - behave.gemspec
66
+ - bin/behave-cli
67
+ - lib/behave.rb
68
+ - lib/behave/version.rb
69
+ - pkg/behave-0.0.1.gem
70
+ - target/maven-archiver/pom.properties
71
+ - target/rubycli-1.0.0-BETA7-SNAPSHOT.jar
72
+ homepage: http://www.hindsighttesting.com
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.24
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Command Line Interface for fetching features and scenarios from the Jira server
99
+ test_files: []
100
+