rspec_term 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0573c8c37f186f9f5d2170eea9bb2c20344d1e6c
4
+ data.tar.gz: 038157f3af222d73df45a3490b3786244a25b825
5
+ SHA512:
6
+ metadata.gz: 577cf4a000a0f3a70bdc52a239989b15e734b75d2fbda2d1171ecf848ec619fdcbca17f1c215d6535df1f8bbb030b47c1fb1eea2ec415b175c2a7119159cc2e8
7
+ data.tar.gz: 142c16b281de75a2ca09c9735a839d26ceda80d5be706fc433580d8f16da64ae7532efe348abcca812cb99d54451eab7b17a6c3f62ea30407c3e4fe26c6bc01f
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec_term.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 brightgenerous
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,63 @@
1
+ # RspecTerm
2
+ ###### ver 0.1.0
3
+
4
+ RSpecを実行中、結果によってiTermの背景画像を変更する ruby gem です。
5
+ RSpec2, RSpec3に対応しています。
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rspec_term'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rspec_term
20
+
21
+ ## Usage
22
+
23
+ spec/spec_helper.rb ファイルに以下を記述します
24
+
25
+
26
+ require 'rspec_term'↲
27
+
28
+ RSpecTerm.configure do |config|↲
29
+
30
+ #dir = File.expand_path(File.join('../', 'images'), File.dirname(__FILE__))
31
+ #config.success_file = "#{dir}/success.jpg"
32
+ #config.running_file = "#{dir}/running.jpg"
33
+ #config.failure_file = "#{dir}/failure.jpg"
34
+ #config.nothing_file = "#{dir}/nothing.jpg"
35
+
36
+ config.success_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/success.jpg'
37
+ config.running_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/running.jpg'
38
+ config.failure_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/failure.jpg'
39
+ config.nothing_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/nothing.jpg'
40
+ config.tmp_dir = '/tmp/rspec_term'
41
+
42
+ end
43
+
44
+ #### 基本的な使い方
45
+
46
+ * `success_file` : テストがエラーなしで終了した場合に表示される画像のファイル。`success_url`よりも優先される。
47
+ * `running_file` : テスト実行中表示される画像のファイル。`running_url`よりも優先される。
48
+ * `failure_file` : テストがエラーありで終了した場合に表示される画像のファイル。`failure_url`よりも優先される。
49
+ * `nothing_file` : 行うべきテストがなかった場合に表示される画像のファイル。`nothing_url`よりも優先される。
50
+ * `success_url` : テストがエラーなしで終了した場合に表示される画像のURL。
51
+ * `running_url` : テスト実行中表示される画像のURL。
52
+ * `failure_url` : テストがエラーありで終了した場合に表示される画像のURL。
53
+ * `nothing_url` : 行うべきテストがなかった場合に表示される画像のURL。
54
+ * `tmp_dir` : URLの画像を保存するディレクトリ。URLから生成したハッシュをファイル名として保存する。すでにファイルが存在する場合は再度ダウンロードしない。
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( http://github.com/<my-github-username>/rspec_term/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'singleton'
3
+
4
+ class RSpecTerm::Configure
5
+
6
+ include Singleton
7
+
8
+ attr_accessor :running_file, :running_url,
9
+ :success_file, :success_url,
10
+ :failure_file, :failure_url,
11
+ :nothing_file, :nothing_url,
12
+ :tmp_dir
13
+
14
+ def self.configure &block
15
+ block.call instance
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,128 @@
1
+ # encoding: utf-8
2
+ require 'rspec/core/formatters/base_formatter'
3
+ require 'fileutils'
4
+ require 'digest/md5'
5
+ require 'open-uri'
6
+
7
+ class RSpecTerm::Formatters::BackgroundFormatter < RSpec::Core::Formatters::BaseFormatter
8
+
9
+ def initialize *args
10
+ super nil
11
+
12
+ @config = args.first
13
+ end
14
+
15
+ private
16
+
17
+ def init
18
+ return self if @inited
19
+
20
+ @tmp_dir = @config.tmp_dir.to_s.strip
21
+ @tmp_dir = '.' if @tmp_dir.empty?
22
+ FileUtils.mkdir_p @tmp_dir unless File.exists? @tmp_dir
23
+
24
+ @success_tmp = url_to_tmp @tmp_dir, @config.success_url
25
+ @running_tmp = url_to_tmp @tmp_dir, @config.running_url
26
+ @failure_tmp = url_to_tmp @tmp_dir, @config.failure_url
27
+ @nothing_tmp = url_to_tmp @tmp_dir, @config.nothing_url
28
+
29
+ @inited = true
30
+ self
31
+ end
32
+
33
+ def url_to_tmp tmp_dir, url
34
+ if url
35
+ "#{tmp_dir}/#{Digest::MD5.hexdigest(url).to_s}"
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ public
42
+
43
+ # if RSpec version is 2.14,
44
+ # then args are expected_example_count
45
+ # if RSpec version is 3.0
46
+ # then args are Notifications::StartNotification
47
+ def start *args
48
+ init
49
+
50
+ unless @error_message
51
+ _file = set_file @config.running_file, @config.running_url, @running_tmp
52
+ _file ||= ''
53
+ change_background _file
54
+ end
55
+ rescue => e
56
+ @error_message = e.inspect
57
+ end
58
+
59
+ # if RSpec version is 2.14,
60
+ # then args are duration, example_count, failure_count, pending_count
61
+ # if RSpec version is 3.0
62
+ # then args are Notifications::SummaryNotification
63
+ def dump_summary *args
64
+ if args.count == 4
65
+ notification = Struct.new(:duration, :example_count, :failure_count, :pending_count).new *args
66
+ else
67
+ notification = args.first
68
+ end
69
+ _dump_summary notification
70
+ p @error_message if @error_message
71
+ end
72
+
73
+ private
74
+
75
+ def _dump_summary notification
76
+ init
77
+
78
+ if notification.example_count == 0
79
+ _file = set_file @config.nothing_file, @config.nothing_url, @nothing_tmp
80
+ _file ||= ''
81
+ change_background _file
82
+ return
83
+ end
84
+
85
+ unless @error_message
86
+ (file, url, tmp) = if notification.failure_count == 0
87
+ [@config.success_file, @config.success_url, "#{@success_tmp}"]
88
+ else
89
+ [@config.failure_file, @config.failure_url, "#{@failure_tmp}"]
90
+ end
91
+ _file = set_file file, url, tmp
92
+ _file ||= ''
93
+ change_background _file
94
+ end
95
+ rescue => e
96
+ @error_message = e.inspect
97
+ end
98
+
99
+ def set_file file, url, tmp
100
+ return file if File.exists? file.to_s
101
+ return tmp if File.exists? tmp.to_s
102
+ return tmp unless url and tmp
103
+
104
+ open tmp, 'wb' do |f|
105
+ open url do |data|
106
+ f.write data.read
107
+ end
108
+ end
109
+ tmp
110
+ end
111
+
112
+ def change_background file
113
+ cmd = <<-EOS
114
+ /usr/bin/osascript <<-EOF
115
+ tell application "iTerm"
116
+ tell the current terminal
117
+ tell the current session
118
+ set background image path to "#{file}"
119
+ end tell
120
+ end tell
121
+ end tell
122
+ EOF
123
+ EOS
124
+ `#{cmd}`
125
+ end
126
+
127
+ end
128
+
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ module RSpecTerm::Formatters
4
+
5
+ autoload :BackgroundFormatter, 'rspec_term/formatters/background_formatter'
6
+
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module RspecTerm
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rspec_term.rb ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module RSpecTerm
4
+
5
+ autoload :Configure, 'rspec_term/configure'
6
+
7
+ autoload :Formatters, 'rspec_term/formatters'
8
+
9
+ def self.configure &block
10
+ Configure.configure &block
11
+ end
12
+
13
+ end
14
+
15
+ RSpec.configure do |config|
16
+ formatter = RSpecTerm::Formatters::BackgroundFormatter.new RSpecTerm::Configure.instance
17
+ config.reporter.register_listener(formatter, :start, :dump_summary)
18
+ end
19
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_term/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec_term"
8
+ spec.version = RspecTerm::VERSION
9
+ spec.authors = ["brightgenerous"]
10
+ spec.email = ["katou.akihiro@gmail.com"]
11
+ spec.summary = %q{iTerm with RSpec}
12
+ spec.description = %q{Change iTerm background after RSpec execution.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
3
+
4
+ describe "RSpecTerm Failure Pleasure" do
5
+
6
+ it do
7
+ sleep rand(10) + 5;
8
+ expect(true).to be false
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
3
+
4
+ describe "RSpecTerm Nothing Pleasure" do
5
+ end
6
+
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
3
+
4
+ describe "RSpecTerm Success Pleasure" do
5
+
6
+ it do
7
+ sleep rand(10) + 5;
8
+ expect(true).to be true
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
3
+
4
+ describe RSpecTerm do
5
+
6
+ describe RSpecTerm::Configure do
7
+ it "arguments" do
8
+ expect{ RSpecTerm::Configure.new }.to raise_error
9
+ expect(RSpecTerm::Configure.instance).not_to be_nil
10
+ methods = [
11
+ :success_file, :success_file=,
12
+ :success_url, :success_url=,
13
+ :running_file, :running_file=,
14
+ :running_url, :running_url=,
15
+ :failure_file, :failure_file=,
16
+ :failure_url, :failure_url=,
17
+ :nothing_file, :nothing_file=,
18
+ :nothing_url, :nothing_url=,
19
+ :tmp_dir, :tmp_dir=
20
+ ]
21
+ expect(methods - RSpecTerm::Configure.instance_methods).to eq []
22
+ end
23
+ end
24
+
25
+ describe RSpecTerm::Formatters::BackgroundFormatter do
26
+ it "`init` method" do
27
+ methods = [
28
+ :start, :dump_summary
29
+ ]
30
+ expect(methods - RSpecTerm::Formatters::BackgroundFormatter.instance_methods).to eq []
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'rspec_term'
3
+
4
+ RSpecTerm.configure do |config|
5
+
6
+ dir = File.expand_path(File.join('../', 'images'), File.dirname(__FILE__))
7
+ # config.success_file = "#{dir}/success.jpg"
8
+ # config.running_file = "#{dir}/running.jpg"
9
+ # config.failure_file = "#{dir}/failure.jpg"
10
+ # config.nothing_file = "#{dir}/nothing.jpg"
11
+
12
+ config.success_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/success.jpg'
13
+ config.running_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/running.jpg'
14
+ config.failure_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/failure.jpg'
15
+ config.nothing_url = 'https://raw.githubusercontent.com/brightgenerous/rspec_term/master/images/nothing.jpg'
16
+ config.tmp_dir = '/tmp/rspec_term'
17
+
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_term
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - brightgenerous
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Change iTerm background after RSpec execution.
42
+ email:
43
+ - katou.akihiro@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - images/failure.jpg
54
+ - images/nothing.jpg
55
+ - images/running.jpg
56
+ - images/success.jpg
57
+ - lib/rspec_term.rb
58
+ - lib/rspec_term/configure.rb
59
+ - lib/rspec_term/formatters.rb
60
+ - lib/rspec_term/formatters/background_formatter.rb
61
+ - lib/rspec_term/version.rb
62
+ - rspec_term.gemspec
63
+ - spec/pleasures/failure_spec_pleasure.rb
64
+ - spec/pleasures/nothing_spec_pleasure.rb
65
+ - spec/pleasures/success_spec_pleasure.rb
66
+ - spec/rspec_term/rspec_term_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: ''
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.14
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: iTerm with RSpec
92
+ test_files:
93
+ - spec/pleasures/failure_spec_pleasure.rb
94
+ - spec/pleasures/nothing_spec_pleasure.rb
95
+ - spec/pleasures/success_spec_pleasure.rb
96
+ - spec/rspec_term/rspec_term_spec.rb
97
+ - spec/spec_helper.rb