rspex 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab08bdbbadaea4655f6b178d70dfa10b0d30e42b
4
+ data.tar.gz: 84d87b8fc74132edb3fbe2fc1c3d97ded5ccb6bf
5
+ SHA512:
6
+ metadata.gz: 4f8e0f336f9e66126c3687f3229fb2cab82620cf1b054bfd6271c07901d41b75b46b04722b918fa110bc06f3b13bfdcb9adb55617131cc63fd38d190125b7ca9
7
+ data.tar.gz: 361be64e0165cc7b43dfb80e3b47d0ba31a88e79ac58c68686ea13d51a329c17a4ebc07aa116adaa1e06f72d9e4b4e0df51d3a0072a486510bbae281ec0a37d5
@@ -0,0 +1 @@
1
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -f d
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'guard-rspec'
5
+ gem 'terminal-notifier-guard'
6
+ gem 'pry-byebug'
7
+
8
+ gemspec
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspex (0.0.1)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (2.3.1)
11
+ columnize (~> 0.3.6)
12
+ debugger-linecache (~> 1.2.0)
13
+ celluloid (0.15.2)
14
+ timers (~> 1.1.0)
15
+ coderay (1.1.0)
16
+ columnize (0.3.6)
17
+ debugger-linecache (1.2.0)
18
+ diff-lcs (1.2.5)
19
+ ffi (1.9.3)
20
+ formatador (0.2.4)
21
+ guard (2.2.4)
22
+ formatador (>= 0.2.4)
23
+ listen (~> 2.1)
24
+ lumberjack (~> 1.0)
25
+ pry (>= 0.9.12)
26
+ thor (>= 0.18.1)
27
+ guard-rspec (4.0.4)
28
+ guard (>= 2.1.1)
29
+ rspec (~> 2.14)
30
+ listen (2.2.0)
31
+ celluloid (>= 0.15.2)
32
+ rb-fsevent (>= 0.9.3)
33
+ rb-inotify (>= 0.9)
34
+ lumberjack (1.0.4)
35
+ method_source (0.8.2)
36
+ pry (0.9.12.3)
37
+ coderay (~> 1.0)
38
+ method_source (~> 0.8)
39
+ slop (~> 3.4)
40
+ pry-byebug (1.2.0)
41
+ byebug (~> 2.2)
42
+ pry (~> 0.9.12)
43
+ rake (10.1.0)
44
+ rb-fsevent (0.9.3)
45
+ rb-inotify (0.9.2)
46
+ ffi (>= 0.5.0)
47
+ rspec (2.14.1)
48
+ rspec-core (~> 2.14.0)
49
+ rspec-expectations (~> 2.14.0)
50
+ rspec-mocks (~> 2.14.0)
51
+ rspec-core (2.14.7)
52
+ rspec-expectations (2.14.4)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.14.4)
55
+ slop (3.4.7)
56
+ terminal-notifier-guard (1.5.3)
57
+ thor (0.18.1)
58
+ timers (1.1.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 1.3)
65
+ guard-rspec
66
+ pry-byebug
67
+ rake
68
+ rspec
69
+ rspex!
70
+ terminal-notifier-guard
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 aq2bq
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.
@@ -0,0 +1,40 @@
1
+ # RSpex
2
+
3
+ Learn how to writing spec in English from local gem's spec-files
4
+
5
+ ![](https://dl.dropboxusercontent.com/u/10198795/rspex_screenshot.png)
6
+
7
+ ## Installation
8
+
9
+ $ gem install rspex
10
+
11
+ ## Usage
12
+
13
+ ### search from 'it' sentence
14
+
15
+ $ rspex it 'keyword'
16
+
17
+
18
+ ### search from 'context' sentence
19
+
20
+ $ rspex context 'keyword'
21
+
22
+
23
+ ### search from 'describe' sentence
24
+
25
+ $ rspex describe 'keyword'
26
+
27
+
28
+ ## TODO
29
+
30
+ 1. Must be Improve performance (It takes 15sec with loading 2500 spec files! )
31
+ 2. Make to configurable
32
+ 3. Use Regular Expression
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspex'
4
+
5
+ RSpex::CLI.start
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fake do
4
+ describe '.create' do
5
+ context "when params are valid" do
6
+ it "returns true" do
7
+ expect(subject).to be_true
8
+ end
9
+ end
10
+ context "when params are invalid" do
11
+ it "returns false" do
12
+ expect(subject).to be_false
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,56 @@
1
+ class RSpecExamples
2
+ SPEC_PATH = "#{Gem.path[0]}/gems/*/spec/**/*_spec.rb"
3
+ attr_reader :examples, :size
4
+
5
+ def initialize(spec_path=SPEC_PATH)
6
+ @examples = Dir.glob(spec_path).map{|path| Example.new(path)}
7
+ end
8
+
9
+ def search word, type
10
+ @examples.select{|example| example.matches word, type }
11
+ end
12
+
13
+ def size
14
+ @examples.size
15
+ end
16
+ end
17
+
18
+
19
+ class Example
20
+ attr_reader :path, :all, :describes, :contexts, :its, :results
21
+
22
+ def initialize path
23
+ raise ('argument must be path to spec file') unless valid?(path)
24
+ @path = path
25
+ @all = open(path).read
26
+ @results = []
27
+ types = %w(describe context it)
28
+ types.each{|type| self.instance_variable_set("@#{type}s",[])}
29
+
30
+ @all.each_line do |line|
31
+ types.each do |type|
32
+ examples(type) << line.chomp.strip if line =~ /.*#{type} .* do$/
33
+ end
34
+ end
35
+ end
36
+
37
+ def name
38
+ @path.match(/^.*gems\/(.*)\/spec\//)[1]
39
+ end
40
+
41
+ def matches word, type
42
+ if examples(type).any?
43
+ @results = examples(type).select{|example| example.include? word}
44
+ end
45
+ @results.any? ? @results : false
46
+ end
47
+
48
+ private
49
+ def examples(type)
50
+ self.instance_variable_get("@#{type}s")
51
+ end
52
+
53
+ def valid?(path)
54
+ Pathname.new(path).exist? and path.include?('spec.rb')
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ require "rspex/version"
2
+ require "rspex/cli"
3
+ require 'rspec_examples'
4
+
5
+ module RSpex
6
+ class << self
7
+ def examples
8
+ @examples = RSpecExamples.new
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ require "rspex"
2
+ require 'thor'
3
+
4
+ module RSpex
5
+ class CLI < Thor
6
+ desc "it 'keyword'", "search keyword from 'it' sentence."
7
+ def it(word)
8
+ search word, 'it'
9
+ end
10
+
11
+ desc "context 'keyword'", "search keyword from 'context' sentence."
12
+ def context(word)
13
+ search word, 'context'
14
+ end
15
+
16
+ desc "describe 'keyword'", "search keyword from 'describe' sentence."
17
+ def describe(word)
18
+ search word, 'describe'
19
+ end
20
+
21
+ private
22
+ def search word, type
23
+ i = 0
24
+ examples = RSpex.examples
25
+ results = examples.search(word, type)
26
+ results.each do |example|
27
+ say("\n[#{example.path}]", :on_blue)
28
+ example.results.each{|result| say(result, :on_black)}
29
+ i += example.results.size
30
+ end
31
+ say("\nfound #{i} example(s) on #{results.size}/#{examples.size} spec(s)", :on_red)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module RSpex
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspex"
8
+ spec.version = RSpex::VERSION
9
+ spec.authors = ["@aq2bq"]
10
+ spec.email = ["terada@yukashikado.co.jp"]
11
+ spec.description = %q{Learn how to writing spec in English from local gem's spec-files}
12
+ spec.summary = %q{Learn how to writing spec in English from local gem's spec-files}
13
+ spec.homepage = "https://twitter.com/aq2bq"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency 'thor'
24
+ end
@@ -0,0 +1,73 @@
1
+ require 'rspec_examples'
2
+
3
+ describe RSpecExamples do
4
+ before do
5
+ @rspec_examples = RSpecExamples.new("fake/gems/*/spec/**/*_spec.rb")
6
+ end
7
+
8
+ let(:word) { 'valid' }
9
+ let(:type) { 'context' }
10
+
11
+ describe '#search' do
12
+ before do
13
+ @search = @rspec_examples.search(word, type)
14
+ end
15
+
16
+ context "Success in Search" do
17
+ it { expect(@search.first.name).to eq "fakegem-1.0.0" }
18
+ it { expect(@search.first.results).to eq ["context \"when params are valid\" do", "context \"when params are invalid\" do"] }
19
+ end
20
+
21
+ context "Fail in Search" do
22
+ let(:type) { 'describe' }
23
+ it { expect(@search).to be_empty }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe Example do
29
+ let(:path) { "fake/gems/fakegem-1.0.0/spec/fake_spec.rb" }
30
+ before do
31
+ @example = Example.new(path)
32
+ end
33
+
34
+ describe '#attr_reader' do
35
+ context "with a valid path" do
36
+ it { expect(@example.all).to eq "require 'spec_helper'\n\n\ndescribe Fake do\n describe '.create' do\n context \"when params are valid\" do\n it \"returns true\" do\n expect(subject).to be_true\n end\n end\n context \"when params are invalid\" do\n it \"returns false\" do\n expect(subject).to be_false\n end\n end\n end\nend\n\n" }
37
+ it { expect(@example.describes).to have(2).items }
38
+ it { expect(@example.describes.first).to eq "describe Fake do" }
39
+ it { expect(@example.contexts).to have(2).items }
40
+ it { expect(@example.contexts.first).to eq "context \"when params are valid\" do" }
41
+ it { expect(@example.its).to have(2).items }
42
+ it { expect(@example.its.first).to eq "it \"returns true\" do" }
43
+ end
44
+ end
45
+
46
+ describe '#name' do
47
+ context "with a valid path" do
48
+ it { expect(@example.name).to eq 'fakegem-1.0.0' }
49
+ end
50
+ context "with an invalid path" do
51
+ it { expect{Example.new('x')}.to raise_error('argument must be path to spec file') }
52
+ end
53
+ end
54
+
55
+ describe '#matches' do
56
+ before do
57
+ @matches = @example.matches(word, type)
58
+ end
59
+ let(:type) { 'context' }
60
+
61
+ context "Success in match the word" do
62
+ let(:word) { 'valid' }
63
+ it { expect(@matches).to have(2).items }
64
+ it { expect(@example.results).to eq ["context \"when params are valid\" do", "context \"when params are invalid\" do"] }
65
+ end
66
+
67
+ context "Fail in match the word" do
68
+ let(:word) { 'xxx' }
69
+ it { expect(@matches).to be_false }
70
+ it { expect(@example.results).to be_empty }
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - '@aq2bq'
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-26 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Learn how to writing spec in English from local gem's spec-files
56
+ email:
57
+ - terada@yukashikado.co.jp
58
+ executables:
59
+ - rspex
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - Guardfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/rspex
72
+ - fake/gems/fakegem-1.0.0/spec/fake_spec.rb
73
+ - lib/rspec_examples.rb
74
+ - lib/rspex.rb
75
+ - lib/rspex/cli.rb
76
+ - lib/rspex/version.rb
77
+ - rspex.gemspec
78
+ - spec/rspec_examples_spec.rb
79
+ homepage: https://twitter.com/aq2bq
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Learn how to writing spec in English from local gem's spec-files
103
+ test_files:
104
+ - spec/rspec_examples_spec.rb