bait 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b73a86de69d8c57f551e895629aa0cda4d0d8c3c
4
- data.tar.gz: b22111f04d15da7b6208386a5c96e751ca638abe
3
+ metadata.gz: 25a481dd7eaf99ce25666d6517669073b3869278
4
+ data.tar.gz: 333a3a8a7c89765b3c68f6bdb12ef4036e81a318
5
5
  SHA512:
6
- metadata.gz: d0f90cd0bd797023b15fdcf5286de496df0dae57bf2f8b4a7be0e848bc2e25f90c7aaf8b6b5f989a62e9c9a1967f692f6948f20ab460f6ea917d03b2e326e402
7
- data.tar.gz: 22d97466385054e47abb15f10ead17c44e5a8baa74361c23a42f1edd43ccc0369332568ed5bb2bdbf1fc0ff4943d27d83f7b0e7be99ceb4e2c0ac7c55c9ad458
6
+ metadata.gz: aa0fed76b8214092e82b98cd08d179d0363ab6e49c697d7926e070bf958833dffa652d26995632973cd19fc64cd76fdf61ab5592d6fa78028b4e5f9d0930ab31
7
+ data.tar.gz: 747d2bda333bd4f8faebaa4e989eff1640cc86cd6724a2ca7150f888afc8cc7dd8b4ac916289fc31260c048a774800ca4659ed81ad2060a80d4a82adc8a80392
@@ -3,5 +3,6 @@ rmts_dir=$(dirname $0)
3
3
  project_dir="$rmts_dir/.."
4
4
  cd $project_dir
5
5
 
6
- bundle
6
+ echo "bundling"
7
+ bundle > /dev/null 2>&1
7
8
  bundle exec rspec spec
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bait (0.3.1)
4
+ bait (0.4.0)
5
+ ansi2html
5
6
  git
6
7
  haml
7
8
  moneta
@@ -19,6 +20,7 @@ GEM
19
20
  i18n (~> 0.6, >= 0.6.4)
20
21
  multi_json (~> 1.0)
21
22
  adapter (0.7.0)
23
+ ansi2html (5.3.4)
22
24
  builder (3.0.4)
23
25
  coderay (1.0.9)
24
26
  daemons (1.1.9)
data/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- 0.3.2
1
+ 0.4.0
2
2
 
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency "git"
33
33
  spec.add_runtime_dependency "haml"
34
34
  spec.add_runtime_dependency "thin"
35
+ spec.add_runtime_dependency 'ansi2html'
35
36
  end
data/bin/bait CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  ENV['RACK_ENV'] = 'production'
3
3
  require 'rubygems'
4
- require 'bait'
5
- require 'bait/api'
6
- Bait::Api.run!
7
-
4
+ require 'bait/cli'
5
+ Bait::CLI.send(ARGV[0] || :server)
@@ -30,7 +30,10 @@ module Bait
30
30
  end
31
31
 
32
32
  post '/build/create' do
33
- build = Build.create(clone_url:params["clone_url"], name:'test')
33
+ build = Build.create({
34
+ clone_url:params["clone_url"],
35
+ name:params["clone_url"].split('/').last
36
+ })
34
37
  build.test_later
35
38
  redirect '/build'
36
39
  end
@@ -43,8 +46,9 @@ module Bait
43
46
  get '/build/retest/:id' do
44
47
  build = Build.find params['id']
45
48
  build.tested = false
46
- build.test_later
49
+ build.output = ""
47
50
  build.save
51
+ build.test_later
48
52
  redirect '/build'
49
53
  end
50
54
  end
@@ -1,16 +1,11 @@
1
- require 'bait'
2
- require 'moneta'
3
- require "toystore"
4
- require 'bait/simple_query'
1
+ require 'bait/object'
5
2
  require 'bait/tester'
3
+ require 'ansi2html/main'
6
4
 
7
5
  module Bait
8
- class Build
9
- include Toy::Store
10
- extend Bait::SimpleQuery
11
-
12
- @@db_file = Bait.db_file('builds')
13
- adapter :memory, Moneta.new(:YAML, :file => @@db_file)
6
+ class Build < Bait::Object
7
+ adapter :memory,
8
+ Moneta.new(:YAML, :file => Bait.db_file('builds'))
14
9
 
15
10
  attribute :ref, String
16
11
  attribute :owner_name, String
@@ -31,11 +26,9 @@ module Bait
31
26
  def test_later
32
27
  self.tested = false
33
28
  self.save
34
- unless Bait.env == "test"
35
- fork do
36
- self.tester.clone!
37
- self.tester.test!
38
- end
29
+ fork do
30
+ self.tester.clone!
31
+ self.tester.test!
39
32
  end
40
33
  self
41
34
  end
@@ -44,7 +37,12 @@ module Bait
44
37
  !self.reload.tested?
45
38
  end
46
39
 
47
- after_destroy { tester.cleanup! }
40
+ def html_output
41
+ out = StringIO.new
42
+ ::ANSI2HTML::Main.new(self.output, out)
43
+ return out.string
44
+ end
48
45
 
46
+ after_destroy { tester.cleanup! }
49
47
  end
50
48
  end
@@ -0,0 +1,56 @@
1
+ module Bait
2
+ module CLI
3
+ USAGE = %{usage:
4
+ * bait .................... alias for bait server
5
+ * bait server ............. start the bait server
6
+ * bait init ............... setup current directory as a bait project
7
+ * bait test ............... simulate this repo being tested with bait}
8
+
9
+ ##
10
+ # Start the server
11
+ def self.server
12
+ puts "Starting bait server"
13
+ require 'bait/api'
14
+ Bait::Api.run!
15
+ end
16
+
17
+ ##
18
+ # Run the test suite script in .bait/test.sh
19
+ def self.test
20
+ script = File.join(Dir.pwd, ".bait", "test.sh")
21
+ unless File.executable? script
22
+ puts "Project did not have executable #{script}"
23
+ puts "Run 'bait init' to create it"
24
+ exit 1
25
+ else
26
+ system(script)
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Create .bait/ and executable .bait/test.sh
32
+ def self.init
33
+ bait_dir = File.join(Dir.pwd, ".bait")
34
+ if File.directory? bait_dir
35
+ puts "Directory already exists: #{bait_dir}"
36
+ else
37
+ script = File.join(bait_dir, 'test.sh')
38
+ FileUtils.mkdir bait_dir
39
+ puts "Created #{bait_dir}"
40
+ File.open(script, 'w') do |f|
41
+ f.puts "#!/bin/bash"
42
+ f.puts "echo edit me"
43
+ end
44
+ File.chmod(0744, script)
45
+ puts "Created executable script #{script}"
46
+ end
47
+ end
48
+
49
+ def self.method_missing method
50
+ unless method.to_sym == :help
51
+ puts "Command not found: #{method}"
52
+ end
53
+ puts USAGE
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ require 'bait'
2
+ require 'moneta'
3
+ require "toystore"
4
+ require 'bait/simple_query'
5
+
6
+ module Bait
7
+ class Object
8
+ include Toy::Store
9
+ extend Bait::SimpleQuery
10
+ end
11
+ end
12
+
@@ -7,5 +7,38 @@ http://yuilibrary.com/license/
7
7
 
8
8
  html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}input,textarea,select{*font-size:100%}legend{color:#000}#yui3-css-stamp.cssreset{display:none}
9
9
 
10
+ .bold {
11
+ font-weight: bold;
12
+ }
13
+ .black {
14
+ color: black;
15
+ }
16
+ .red {
17
+ color: red;
18
+ }
19
+ .green {
20
+ color: green;
21
+ }
22
+ .yellow {
23
+ color: yellow;
24
+ }
25
+ .blue {
26
+ color: blue;
27
+ }
28
+ .magenta {
29
+ color: magenta;
30
+ }
31
+ .cyan {
32
+ color: cyan;
33
+ }
34
+ .white {
35
+ color: white;
36
+ }
37
+ .grey {
38
+ color: grey;
39
+ }
10
40
 
11
-
41
+ .build .output {
42
+ color:white;
43
+ background-color:black;
44
+ }
@@ -10,12 +10,17 @@ module Bait
10
10
  self.class.ids = self.class.ids.reject{|id| id == self.id}
11
11
  end
12
12
  end
13
+
14
+ def id_list_key
15
+ "#{self.name.split('::').last.downcase}_ids"
16
+ end
17
+
13
18
  def ids
14
- Bait.store.raw["build_ids"] ||= []
19
+ Bait.store.raw[id_list_key] ||= []
15
20
  end
16
21
 
17
22
  def ids=(new_ids)
18
- Bait.store.raw["build_ids"] = new_ids
23
+ Bait.store.raw[id_list_key] = new_ids
19
24
  end
20
25
 
21
26
  def all
@@ -1,7 +1,7 @@
1
1
  require 'bait'
2
2
  require 'bait/build'
3
3
  require 'git'
4
- require 'pty'
4
+ require 'open3'
5
5
 
6
6
  module Bait
7
7
  class Tester
@@ -20,22 +20,15 @@ module Bait
20
20
  end
21
21
 
22
22
  def test!
23
- begin
24
- begin
25
- PTY.spawn(script) do |r, w, pid|
26
- r.each { |line| @build.output << line }
27
- @build.passed = PTY.check(pid).exitstatus == 0
28
- end
29
- rescue PTY::ChildExited => e
30
- @build.output << e
31
- @build.passed = false
32
- end
33
- @build.tested = true
34
- rescue Errno::ENOENT => ex
35
- @build.output << "A test script was expected but missing.\nError: #{ex.message}"
36
- ensure
37
- @build.save
23
+ Open3.popen2e(script) do |stdin, oe, wait_thr|
24
+ oe.each {|line| @build.output << line }
25
+ @build.passed = wait_thr.value.exitstatus == 0
38
26
  end
27
+ @build.tested = true
28
+ rescue Errno::ENOENT => ex
29
+ @build.output << "A test script was expected but missing.\nError: #{ex.message}"
30
+ ensure
31
+ @build.save
39
32
  end
40
33
 
41
34
  def clone_path
@@ -48,8 +41,7 @@ module Bait
48
41
  Git.clone(@build.clone_url, @build.name, :path => sandbox_directory)
49
42
  rescue => ex
50
43
  msg = "Failed to clone #{@build.clone_url}"
51
- puts msg
52
- @build.stderr = "#{msg}\n\n#{ex.message}\n\n#{ex.backtrace}"
44
+ @build.output << "#{msg}\n\n#{ex.message}\n\n#{ex.backtrace}"
53
45
  @build.save
54
46
  end
55
47
  end
@@ -1,7 +1,7 @@
1
1
  Listing Builds
2
2
  %ul
3
3
  - @builds.each do |build|
4
- %li
4
+ %li.build
5
5
  %hr
6
6
  .name= build.name
7
7
  %a.clone_url{href:build.clone_url}= build.clone_url
@@ -12,9 +12,7 @@ Listing Builds
12
12
  = build.passed? ? "Passed!" : "Failed!"
13
13
  - else
14
14
  Queued
15
- .output
16
- Output:
17
- %pre= build.output
15
+ %pre.output= build.html_output
18
16
  .actions
19
17
  %a{href:"/build/remove/#{build.id}"} Remove
20
18
  %a{href:"/build/retest/#{build.id}"} Retest
@@ -1,18 +1,19 @@
1
1
  require 'spec_helper'
2
2
  require 'bait/api'
3
- require 'bait/build'
4
3
 
5
- describe "Sinatra App" do
4
+ describe Bait::Api do
6
5
  let(:app) { Bait::Api }
7
6
  subject { last_response }
8
7
 
8
+ let (:build) { Bait::Build.last }
9
+
9
10
  describe "github post-receive hook" do
10
11
  let(:github_json) do
11
12
  <<-GITHUB_JSON
12
13
  {
13
14
  "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
14
15
  "repository": {
15
- "url": "http://github.com/defunkt/github",
16
+ "url": "http://github.com/keyvanfatehi/bait",
16
17
  "name": "github",
17
18
  "owner": {
18
19
  "email": "chris@ozmm.org",
@@ -45,8 +46,6 @@ describe "Sinatra App" do
45
46
  GITHUB_JSON
46
47
  end
47
48
 
48
- let (:build) { Bait::Build.last }
49
-
50
49
  describe "POST /" do
51
50
  before do
52
51
  post '/', payload: github_json
@@ -61,65 +60,69 @@ describe "Sinatra App" do
61
60
  build.ref.should eq "refs/heads/master"
62
61
  end
63
62
 
64
- it { build.should be_queued }
63
+ specify { build.should be_queued }
65
64
  end
65
+ end
66
66
 
67
- describe "GET /" do
68
- before { get '/' }
69
- it { should be_redirect }
70
- end
67
+ describe "GET /" do
68
+ before { get '/' }
69
+ it { should be_redirect }
70
+ end
71
71
 
72
- describe "GET /build" do
73
- before do
74
- Bait::Build.create(name: "quickfox", clone_url:'...')
75
- Bait::Build.create(name: "slowsloth", clone_url:'...')
76
- get '/build'
77
- end
72
+ describe "GET /build" do
73
+ before do
74
+ Bait::Build.create(name: "quickfox", clone_url:'...')
75
+ Bait::Build.create(name: "slowsloth", clone_url:'...')
76
+ get '/build'
77
+ end
78
78
 
79
- it { should be_ok }
79
+ it { should be_ok }
80
80
 
81
- it "shows the builds" do
82
- subject.body.should match /quickfox/
83
- subject.body.should match /slowsloth/
84
- end
81
+ it "shows the builds" do
82
+ subject.body.should match /quickfox/
83
+ subject.body.should match /slowsloth/
85
84
  end
85
+ end
86
86
 
87
- describe "POST /build/create" do
88
- let(:test_url){ "http://github.com/defunkt/github" }
89
- before do
90
- post '/build/create', {clone_url:test_url}
91
- end
92
- it "can create a build manually" do
93
- build.clone_url.should eq test_url
94
- end
95
- specify { build.should be_queued }
87
+ describe "POST /build/create" do
88
+ let(:test_url){ repo_path }
89
+ before do
90
+ post '/build/create', {clone_url:test_url}
96
91
  end
92
+ specify { build.clone_url.should eq test_url }
93
+ specify { build.name.should match(/^bait/) }
94
+ specify { build.should be_queued }
95
+ end
97
96
 
98
- describe "GET /build/remove/#" do
99
- before do
100
- @build = Bait::Build.create(name: "quickfox", clone_url:'...')
101
- @sandbox = @build.tester.sandbox_directory
102
- get "/build/remove/#{@build.id}"
103
- end
104
- it "removes the build from store and its files from the filesystem" do
105
- expect{@build.reload}.to raise_error Toy::NotFound
106
- Bait::Build.ids.should be_empty
107
- Pathname.new(@sandbox).should_not exist
108
- end
109
- it { should be_redirect }
97
+ describe "GET /build/remove/#" do
98
+ before do
99
+ @build = Bait::Build.create(name: "quickfox", clone_url:'...')
100
+ @sandbox = @build.tester.sandbox_directory
101
+ get "/build/remove/#{@build.id}"
102
+ end
103
+ it "removes the build from store and its files from the filesystem" do
104
+ expect{@build.reload}.to raise_error Toy::NotFound
105
+ Bait::Build.ids.should be_empty
106
+ Pathname.new(@sandbox).should_not exist
110
107
  end
108
+ it { should be_redirect }
109
+ end
111
110
 
112
- describe "GET /build/retest/#" do
113
- before do
114
- @build = Bait::Build.create(name: "quickfox", clone_url:'...')
115
- @build.tested = true
116
- @build.save
117
- get "/build/retest/#{@build.id}"
118
- end
119
- it "queues the build for retesting" do
120
- build.should be_queued
121
- end
122
- it { should be_redirect }
111
+ describe "GET /build/retest/#" do
112
+ before do
113
+ @build = Bait::Build.create(name: "quickfox", clone_url:'...')
114
+ @build.tested = true
115
+ @build.output = "bla bla old output"
116
+ @build.save
117
+ get "/build/retest/#{@build.id}"
118
+ @build.reload
119
+ end
120
+ it "queues the build for retesting" do
121
+ @build.should be_queued
122
+ end
123
+ it "clears the previous output" do
124
+ @build.output.should be_blank
123
125
  end
126
+ it { should be_redirect }
124
127
  end
125
128
  end
@@ -41,6 +41,17 @@ describe Bait::Build do
41
41
 
42
42
  let (:build) { Bait::Build.create(name: "app", clone_url:'...') }
43
43
 
44
+ describe "#test_later" do
45
+ it "forks in order to clone and test" do
46
+ build.should_receive(:fork) do |&block|
47
+ build.tester.should_receive(:clone!)
48
+ build.tester.should_receive(:test!)
49
+ block.call
50
+ end
51
+ build.test_later
52
+ end
53
+ end
54
+
44
55
  describe "#tester" do
45
56
  specify { build.tester.should be_a Bait::Tester }
46
57
  end
@@ -75,4 +86,9 @@ describe Bait::Build do
75
86
  it { should be_queued }
76
87
  end
77
88
  end
89
+
90
+ describe "#html_output" do
91
+ before { build.output = "\e[33mHello\e[0m" ; build.save }
92
+ specify { build.html_output.should eq %{<span class="yellow">Hello</span>} }
93
+ end
78
94
  end
@@ -2,10 +2,6 @@ require 'spec_helper'
2
2
  require 'bait/tester'
3
3
 
4
4
  describe Bait::Tester do
5
- let(:repo_path) do
6
- path = File.join(File.dirname(__FILE__), '..', '..', '..')
7
- File.expand_path(path)
8
- end
9
5
  let(:build) { Bait::Build.create(name: "bait", clone_url:repo_path) }
10
6
  let(:tester) { build.tester }
11
7
 
@@ -24,8 +20,17 @@ describe Bait::Tester do
24
20
  end
25
21
 
26
22
  describe "#clone!" do
27
- before { tester.clone! }
28
- specify { tester.should be_cloned }
23
+ context 'valid clone url' do
24
+ before { tester.clone! }
25
+ specify { build.output.should_not match /Failed to clone/ }
26
+ specify { tester.should be_cloned }
27
+ end
28
+ context "invalid clone url" do
29
+ let(:build) { Bait::Build.create(name: "bait", clone_url:'invalid') }
30
+ before { tester.clone! }
31
+ specify { build.output.should match /Failed to clone/ }
32
+ specify { tester.should_not be_cloned }
33
+ end
29
34
  end
30
35
 
31
36
  describe "#test!" do
@@ -50,7 +55,7 @@ describe Bait::Tester do
50
55
  tester.test!
51
56
  end
52
57
  it { should_not be_tested }
53
- it "has Bait errors in output" do
58
+ it "has errors in output" do
54
59
  subject.output.should match /script was expected but missing/
55
60
  end
56
61
  end
@@ -2,9 +2,20 @@ ENV['RACK_ENV'] = "test"
2
2
  require 'simplecov'
3
3
  SimpleCov.start
4
4
 
5
+ # Use simplecov with forking specs
6
+ pid = Process.pid
7
+ SimpleCov.at_exit do
8
+ SimpleCov.result.format! if Process.pid == pid
9
+ end
10
+
5
11
  require 'bait'
6
12
  require 'fileutils'
7
13
 
14
+ def repo_path
15
+ path = File.join(File.dirname(__FILE__), '..')
16
+ File.expand_path(path)
17
+ end
18
+
8
19
  def clear_storage
9
20
  FileUtils.rm_rf Bait.storage_dir
10
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bait
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keyvan Fatehi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - '>='
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: ansi2html
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: Accepts github push event webhook to clone and execute .bait/test.sh
196
210
  email:
197
211
  - keyvan@digitalfilmtree.com
@@ -202,7 +216,7 @@ extra_rdoc_files: []
202
216
  files:
203
217
  - .bait/test.sh
204
218
  - .gitignore
205
- - DEVELOP
219
+ - .rspec
206
220
  - Gemfile
207
221
  - Gemfile.lock
208
222
  - Guardfile
@@ -215,9 +229,8 @@ files:
215
229
  - lib/bait.rb
216
230
  - lib/bait/api.rb
217
231
  - lib/bait/build.rb
218
- - lib/bait/objective_c/dependency_orderer.rb
219
- - lib/bait/objective_c/project.rb
220
- - lib/bait/project.rb
232
+ - lib/bait/cli.rb
233
+ - lib/bait/object.rb
221
234
  - lib/bait/public/css/styles.css
222
235
  - lib/bait/simple_query.rb
223
236
  - lib/bait/tester.rb
@@ -226,9 +239,6 @@ files:
226
239
  - lib/bait/views/layout.haml
227
240
  - spec/lib/bait/api_spec.rb
228
241
  - spec/lib/bait/build_spec.rb
229
- - spec/lib/bait/objective_c/dependency_orderer_spec.rb
230
- - spec/lib/bait/objective_c/project_spec.rb
231
- - spec/lib/bait/project_spec.rb
232
242
  - spec/lib/bait/tester_spec.rb
233
243
  - spec/lib/bait_spec.rb
234
244
  - spec/spec_helper.rb
@@ -253,16 +263,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
263
  version: '0'
254
264
  requirements: []
255
265
  rubyforge_project:
256
- rubygems_version: 2.0.5
266
+ rubygems_version: 2.0.3
257
267
  signing_key:
258
268
  specification_version: 4
259
269
  summary: build and integration test service
260
270
  test_files:
261
271
  - spec/lib/bait/api_spec.rb
262
272
  - spec/lib/bait/build_spec.rb
263
- - spec/lib/bait/objective_c/dependency_orderer_spec.rb
264
- - spec/lib/bait/objective_c/project_spec.rb
265
- - spec/lib/bait/project_spec.rb
266
273
  - spec/lib/bait/tester_spec.rb
267
274
  - spec/lib/bait_spec.rb
268
275
  - spec/spec_helper.rb
data/DEVELOP DELETED
@@ -1,5 +0,0 @@
1
- Write the specs
2
-
3
- http://www.sinatrarb.com/testing.html
4
- https://github.com/raggi/github_post_receive_server/blob/master/spec/github_post_receive_server/rack_app_spec.rb
5
-
@@ -1,48 +0,0 @@
1
- require 'bait/objective_c/project'
2
-
3
- module Bait
4
- module ObjectiveC
5
- class DependencyOrderer
6
- attr_accessor :errors, :order, :queue, :project
7
- def initialize path_array, project
8
- @project = project
9
- @queue = path_array
10
- @order = []
11
- @errors = []
12
- end
13
-
14
- def examine_file path
15
- return unless path && File.exists?(path)
16
- if @order.include? path
17
- return
18
- end
19
- imports_within(path).each do |name|
20
- examine_file @project.glob(name).first
21
- end
22
- @order << path
23
- end
24
-
25
- def imports_within path
26
- imports = []
27
- File.open(path, 'r') do |f|
28
- f.each_line do |line|
29
- if matches = line.match(/^#import "(.*)"/)
30
- imports << matches[1]
31
- end
32
- end
33
- end
34
- rescue => ex
35
- @errors << ex
36
- ensure
37
- return imports
38
- end
39
-
40
- def start
41
- @queue.each do |path|
42
- examine_file path
43
- end
44
- end
45
- end
46
- end
47
- end
48
-
@@ -1,17 +0,0 @@
1
- require 'bait/project'
2
- require 'bait/objective_c/dependency_orderer'
3
-
4
- module Bait
5
- module ObjectiveC
6
- class Project < Bait::Project
7
- def h_files
8
- @h_files ||= ordered_dependencies '*.h', ObjectiveC::DependencyOrderer
9
- end
10
-
11
- def m_files
12
- @m_files ||= ordered_dependencies '*.m', ObjectiveC::DependencyOrderer
13
- end
14
- end
15
- end
16
- end
17
-
@@ -1,25 +0,0 @@
1
- module Bait
2
- class Project
3
- def initialize root_path
4
- unless Dir.exists? root_path
5
- raise "Expected a valid directory"
6
- end
7
- @path = Pathname.new(root_path)
8
- end
9
-
10
- def glob pattern
11
- cache ||= {}
12
- if value = cache[pattern]
13
- value
14
- else
15
- cache[pattern] = Dir.glob @path.join("**/#{pattern}")
16
- end
17
- end
18
-
19
- def ordered_dependencies file_pattern, klass
20
- orderer = klass.new(glob(file_pattern), self)
21
- orderer.start
22
- orderer.order
23
- end
24
- end
25
- end
@@ -1,8 +0,0 @@
1
- require 'bait/objective_c/dependency_orderer'
2
-
3
- describe Bait::ObjectiveC::DependencyOrderer do
4
- it "initializes with a path array and a Bait::Project" do
5
- project = Bait::ObjectiveC::Project.new File.dirname(__FILE__)
6
- Bait::ObjectiveC::DependencyOrderer.new [], project
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require 'bait/objective_c/project'
2
-
3
- describe Bait::ObjectiveC::Project do
4
- subject { Bait::ObjectiveC::Project.new "/" }
5
- it { should respond_to :h_files }
6
- it { should respond_to :m_files }
7
- end
8
-
@@ -1,8 +0,0 @@
1
- require 'bait/project'
2
-
3
- describe Bait::Project do
4
- it "requires a valid root path" do
5
- expect { Bait::Project.new('fawfewa') }.to raise_error
6
- expect { Bait::Project.new('/') }.not_to raise_error
7
- end
8
- end