transpec 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -7
- data/CHANGELOG.md +4 -0
- data/README.md +58 -12
- data/README.md.erb +58 -12
- data/lib/transpec/cli.rb +10 -12
- data/lib/transpec/context.rb +98 -49
- data/lib/transpec/syntax/method_stub.rb +1 -1
- data/lib/transpec/syntax/rspec_configure.rb +21 -20
- data/lib/transpec/syntax/should.rb +1 -1
- data/lib/transpec/syntax/should_receive.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/.rubocop.yml +4 -0
- data/spec/support/shared_context.rb +1 -1
- data/spec/transpec/context_spec.rb +497 -109
- data/spec/transpec/syntax/method_stub_spec.rb +2 -3
- data/spec/transpec/syntax/should_receive_spec.rb +2 -2
- data/spec/transpec/syntax/should_spec.rb +1 -1
- data/tasks/demo.rake +23 -0
- data/tasks/lib/transpec_demo.rb +51 -0
- data/tasks/lib/transpec_test.rb +148 -0
- data/tasks/test.rake +3 -151
- data/transpec.gemspec +1 -1
- metadata +7 -4
@@ -9,7 +9,7 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:method_stub_object) do
|
12
|
-
AST::Scanner.scan(ast) do |node, ancestor_nodes
|
12
|
+
AST::Scanner.scan(ast) do |node, ancestor_nodes|
|
13
13
|
next unless MethodStub.target_node?(node)
|
14
14
|
return MethodStub.new(
|
15
15
|
node,
|
@@ -92,7 +92,7 @@ module Transpec
|
|
92
92
|
|
93
93
|
describe '#allowize!' do
|
94
94
|
before do
|
95
|
-
method_stub_object.context.stub(:
|
95
|
+
method_stub_object.context.stub(:allow_to_receive_available?).and_return(true)
|
96
96
|
method_stub_object.allowize!
|
97
97
|
end
|
98
98
|
|
@@ -389,7 +389,6 @@ module Transpec
|
|
389
389
|
|
390
390
|
describe '#replace_deprecated_method!' do
|
391
391
|
before do
|
392
|
-
method_stub_object.context.stub(:in_example_group?).and_return(true)
|
393
392
|
method_stub_object.replace_deprecated_method!
|
394
393
|
end
|
395
394
|
|
@@ -9,7 +9,7 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
|
11
11
|
subject(:should_receive_object) do
|
12
|
-
AST::Scanner.scan(ast) do |node, ancestor_nodes
|
12
|
+
AST::Scanner.scan(ast) do |node, ancestor_nodes|
|
13
13
|
next unless ShouldReceive.target_node?(node)
|
14
14
|
return ShouldReceive.new(
|
15
15
|
node,
|
@@ -23,7 +23,7 @@ module Transpec
|
|
23
23
|
let(:record) { should_receive_object.report.records.first }
|
24
24
|
|
25
25
|
before do
|
26
|
-
should_receive_object.context.stub(:
|
26
|
+
should_receive_object.context.stub(:non_monkey_patch_mock_available?).and_return(true)
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '#expectize!' do
|
@@ -12,7 +12,7 @@ module Transpec
|
|
12
12
|
let(:record) { should_object.report.records.first }
|
13
13
|
|
14
14
|
before do
|
15
|
-
should_object.context.stub(:
|
15
|
+
should_object.context.stub(:expect_to_matcher_available?).and_return(true)
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '#matcher_node' do
|
data/tasks/demo.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'lib/transpec_demo'
|
4
|
+
|
5
|
+
namespace :demo do
|
6
|
+
# rubocop:disable LineLength
|
7
|
+
demos = [
|
8
|
+
TranspecDemo.new('git@github.com:yujinakayama/twitter.git', 'v4.1.0'),
|
9
|
+
TranspecDemo.new('git@github.com:yujinakayama/guard.git', 'transpec-test', %w(--without development)),
|
10
|
+
TranspecDemo.new('git@github.com:yujinakayama/mail.git', 'transpec-test')
|
11
|
+
]
|
12
|
+
# rubocop:enable LineLength
|
13
|
+
|
14
|
+
desc 'Run demo of Transpec on all projects'
|
15
|
+
task all: demos.map(&:name)
|
16
|
+
|
17
|
+
demos.each do |demo|
|
18
|
+
desc "Run demo of Transpec on #{demo.name.capitalize} project"
|
19
|
+
task demo.name do
|
20
|
+
demo.run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require_relative 'transpec_test'
|
4
|
+
|
5
|
+
class TranspecDemo < TranspecTest
|
6
|
+
DEMO_BRANCH = 'transpec-demo'
|
7
|
+
|
8
|
+
def self.base_dir_path
|
9
|
+
@base_dir_path = File.join('tmp', 'demos')
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
require 'transpec'
|
14
|
+
|
15
|
+
puts " Running demo on #{name} Project ".center(80, '=')
|
16
|
+
|
17
|
+
prepare_project
|
18
|
+
run_demo
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def prepare_with_git_repo
|
24
|
+
super
|
25
|
+
git_branch_delete(DEMO_BRANCH) if git_local_branch_exist?(DEMO_BRANCH)
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_demo(transpec_args = [])
|
29
|
+
in_project_dir do
|
30
|
+
with_clean_bundler_env do
|
31
|
+
sh File.join(Transpec.root, 'bin', 'transpec'), '--force', '--commit-message'
|
32
|
+
sh 'bundle exec rspec'
|
33
|
+
sh "git checkout --quiet -b #{DEMO_BRANCH}"
|
34
|
+
sh 'git commit --all --file .git/COMMIT_EDITMSG'
|
35
|
+
sh "git push --force origin #{DEMO_BRANCH}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def git_local_branch_exist?(branch_name)
|
41
|
+
in_project_dir do
|
42
|
+
system('git', 'show-ref', '--verify', '--quiet', "refs/heads/#{branch_name}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def git_branch_delete(branch_name)
|
47
|
+
in_project_dir do
|
48
|
+
sh "git branch -D #{branch_name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class TranspecTest
|
4
|
+
include FileUtils # This is Rake's one.
|
5
|
+
|
6
|
+
attr_reader :url, :ref, :bundler_args
|
7
|
+
|
8
|
+
def self.base_dir
|
9
|
+
@base_dir ||= begin
|
10
|
+
unless Dir.exist?(base_dir_path)
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.mkdir_p(base_dir_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
base_dir_path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.base_dir_path
|
20
|
+
@base_dir_path = File.join('tmp', 'tests')
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(url, ref = nil, bundler_args = [])
|
24
|
+
@url = url
|
25
|
+
@ref = ref
|
26
|
+
@bundler_args = bundler_args
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
@name ||= File.basename(url, '.git')
|
31
|
+
end
|
32
|
+
|
33
|
+
def project_dir
|
34
|
+
@project_dir ||= File.join(self.class.base_dir, name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
require 'transpec'
|
39
|
+
|
40
|
+
puts " Testing on #{name} Project ".center(80, '=')
|
41
|
+
|
42
|
+
[%w(--force), %w(--force --no-parentheses-matcher-arg)].each do |args|
|
43
|
+
prepare_project
|
44
|
+
run_test(args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def prepare_project
|
51
|
+
if url.start_with?('/')
|
52
|
+
prepare_with_local_dir
|
53
|
+
else
|
54
|
+
prepare_with_git_repo
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def prepare_with_local_dir
|
59
|
+
if Dir.exist?(project_dir)
|
60
|
+
require 'fileutils'
|
61
|
+
FileUtils.rm_rf(project_dir)
|
62
|
+
end
|
63
|
+
|
64
|
+
Dir.mkdir(project_dir)
|
65
|
+
|
66
|
+
Dir.chdir(url) do
|
67
|
+
Dir.new('.').each do |entry|
|
68
|
+
next if ['.', '..', '.git', 'tmp'].include?(entry)
|
69
|
+
FileUtils.cp_r(entry, project_dir)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
bundle_install
|
74
|
+
end
|
75
|
+
|
76
|
+
def prepare_with_git_repo
|
77
|
+
if Dir.exist?(project_dir)
|
78
|
+
git_checkout(ref) unless current_ref == ref
|
79
|
+
git_checkout('.')
|
80
|
+
else
|
81
|
+
git_clone
|
82
|
+
bundle_install
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def run_test(transpec_args = [])
|
87
|
+
in_project_dir do
|
88
|
+
with_clean_bundler_env do
|
89
|
+
sh File.join(Transpec.root, 'bin', 'transpec'), *transpec_args
|
90
|
+
sh 'bundle exec rspec'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def in_project_dir(&block)
|
96
|
+
Dir.chdir(project_dir, &block)
|
97
|
+
end
|
98
|
+
|
99
|
+
def current_ref
|
100
|
+
in_project_dir do
|
101
|
+
`git describe --all`.chomp.sub(/\Aheads\//, '')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def git_checkout(*args)
|
106
|
+
in_project_dir do
|
107
|
+
sh 'git', 'checkout', *args
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def git_clone
|
112
|
+
Dir.chdir(self.class.base_dir) do
|
113
|
+
# Disabling checkout here to suppress "detached HEAD" warning.
|
114
|
+
sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
|
115
|
+
end
|
116
|
+
|
117
|
+
in_project_dir do
|
118
|
+
sh "git checkout --quiet #{ref}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def bundle_install
|
123
|
+
in_project_dir do
|
124
|
+
with_clean_bundler_env do
|
125
|
+
sh 'bundle', 'install', *bundler_args
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def with_clean_bundler_env
|
131
|
+
if defined?(Bundler)
|
132
|
+
Bundler.with_clean_env do
|
133
|
+
# Bundler.with_clean_env cleans environment variables
|
134
|
+
# which are set after bundler is loaded.
|
135
|
+
prepare_env
|
136
|
+
yield
|
137
|
+
end
|
138
|
+
else
|
139
|
+
prepare_env
|
140
|
+
yield
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def prepare_env
|
145
|
+
# Disable Coveralls.
|
146
|
+
ENV['CI'] = ENV['JENKINS_URL'] = ENV['COVERALLS_RUN_LOCALLY'] = nil
|
147
|
+
end
|
148
|
+
end
|
data/tasks/test.rake
CHANGED
@@ -1,154 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
include FileUtils # This is Rake's one.
|
5
|
-
|
6
|
-
attr_reader :url, :ref, :bundler_args
|
7
|
-
|
8
|
-
def self.base_dir
|
9
|
-
@base_dir ||= begin
|
10
|
-
base_dir = File.join('tmp', 'projects')
|
11
|
-
|
12
|
-
unless Dir.exist?(base_dir)
|
13
|
-
require 'fileutils'
|
14
|
-
FileUtils.mkdir_p(base_dir)
|
15
|
-
end
|
16
|
-
|
17
|
-
base_dir
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def initialize(url, ref = nil, bundler_args = [])
|
22
|
-
@url = url
|
23
|
-
@ref = ref
|
24
|
-
@bundler_args = bundler_args
|
25
|
-
end
|
26
|
-
|
27
|
-
def name
|
28
|
-
@name ||= File.basename(url, '.git')
|
29
|
-
end
|
30
|
-
|
31
|
-
def project_dir
|
32
|
-
@project_dir ||= File.join(self.class.base_dir, name)
|
33
|
-
end
|
34
|
-
|
35
|
-
def run
|
36
|
-
require 'transpec'
|
37
|
-
|
38
|
-
puts " Testing on #{name} Project ".center(80, '=')
|
39
|
-
|
40
|
-
[%w(--force), %w(--force --no-parentheses-matcher-arg)].each do |args|
|
41
|
-
prepare_project
|
42
|
-
run_test(args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def prepare_project
|
49
|
-
if url.start_with?('/')
|
50
|
-
prepare_with_local_dir
|
51
|
-
else
|
52
|
-
prepare_with_git_repo
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def prepare_with_local_dir
|
57
|
-
if Dir.exist?(project_dir)
|
58
|
-
require 'fileutils'
|
59
|
-
FileUtils.rm_rf(project_dir)
|
60
|
-
end
|
61
|
-
|
62
|
-
Dir.mkdir(project_dir)
|
63
|
-
|
64
|
-
Dir.chdir(url) do
|
65
|
-
Dir.new('.').each do |entry|
|
66
|
-
next if ['.', '..', '.git', 'tmp'].include?(entry)
|
67
|
-
FileUtils.cp_r(entry, project_dir)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
bundle_install
|
72
|
-
end
|
73
|
-
|
74
|
-
def prepare_with_git_repo
|
75
|
-
if Dir.exist?(project_dir)
|
76
|
-
if current_ref == ref
|
77
|
-
git_reset_hard
|
78
|
-
return
|
79
|
-
else
|
80
|
-
require 'fileutils'
|
81
|
-
FileUtils.rm_rf(project_dir)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
git_clone
|
86
|
-
bundle_install
|
87
|
-
end
|
88
|
-
|
89
|
-
def run_test(transpec_args = [])
|
90
|
-
in_project_dir do
|
91
|
-
with_clean_bundler_env do
|
92
|
-
sh File.join(Transpec.root, 'bin', 'transpec'), *transpec_args
|
93
|
-
sh 'bundle exec rspec'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def in_project_dir(&block)
|
99
|
-
Dir.chdir(project_dir, &block)
|
100
|
-
end
|
101
|
-
|
102
|
-
def current_ref
|
103
|
-
in_project_dir do
|
104
|
-
`git describe --all`.chomp.sub(/\Aheads\//, '')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def git_reset_hard
|
109
|
-
in_project_dir do
|
110
|
-
sh 'git reset --hard'
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def git_clone
|
115
|
-
Dir.chdir(self.class.base_dir) do
|
116
|
-
# Disabling checkout here to suppress "detached HEAD" warning.
|
117
|
-
sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
|
118
|
-
end
|
119
|
-
|
120
|
-
in_project_dir do
|
121
|
-
sh "git checkout --quiet #{ref}"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def bundle_install
|
126
|
-
in_project_dir do
|
127
|
-
with_clean_bundler_env do
|
128
|
-
sh 'bundle', 'install', *bundler_args
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def with_clean_bundler_env
|
134
|
-
if defined?(Bundler)
|
135
|
-
Bundler.with_clean_env do
|
136
|
-
# Bundler.with_clean_env cleans environment variables
|
137
|
-
# which are set after bundler is loaded.
|
138
|
-
prepare_env
|
139
|
-
yield
|
140
|
-
end
|
141
|
-
else
|
142
|
-
prepare_env
|
143
|
-
yield
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def prepare_env
|
148
|
-
# Disable Coveralls.
|
149
|
-
ENV['CI'] = ENV['JENKINS_URL'] = ENV['COVERALLS_RUN_LOCALLY'] = nil
|
150
|
-
end
|
151
|
-
end
|
3
|
+
require_relative 'lib/transpec_test'
|
152
4
|
|
153
5
|
namespace :test do
|
154
6
|
# On Travis CI, reuse system gems to speed up build.
|
@@ -162,8 +14,8 @@ namespace :test do
|
|
162
14
|
tests = [
|
163
15
|
TranspecTest.new(File.expand_path('.'), nil, ['--quiet']),
|
164
16
|
TranspecTest.new('https://github.com/sferik/twitter.git', 'v4.1.0', bundler_args),
|
165
|
-
TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec', bundler_args + %w(--without development)),
|
166
|
-
TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec', bundler_args)
|
17
|
+
TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec-test', bundler_args + %w(--without development)),
|
18
|
+
TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec-test', bundler_args)
|
167
19
|
]
|
168
20
|
# rubocop:enable LineLength
|
169
21
|
|
data/transpec.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.1'
|
28
28
|
spec.add_development_dependency 'simplecov', '~> 0.7'
|
29
29
|
spec.add_development_dependency 'rubocop', '~> 0.10'
|
30
|
-
spec.add_development_dependency 'guard-rspec', '~>
|
30
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.0'
|
31
31
|
spec.add_development_dependency 'guard-rubocop', '~> 1.0'
|
32
32
|
spec.add_development_dependency 'guard-shell', '~> 0.5'
|
33
33
|
spec.add_development_dependency 'ruby_gntp', '~> 0.3'
|