siyousho 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: 7c73ccfdfa5b19f7980328f06c5f33837ec2aa8b535a18f97dad017e4f94c784
4
- data.tar.gz: 92832dafcb5e1fb4d7891cb06d528f3cf71f981b2573e41cc6edd7546c0d1574
3
+ metadata.gz: 483630747b5e4867c4c66618a9aa7d9c2834b9ee8394b3ecabdfeaab29d4c472
4
+ data.tar.gz: 99b7d1d59fd3e1d8132224e33c6f9c736f75afdd08559175187d6dd9a992401d
5
5
  SHA512:
6
- metadata.gz: 3961f3e7ffcf10df95a3a8d2fb3643e60bd40ad860a2bab7a68bfd4f1892915e95251a087851583017495f9a0fd3a0200838e3a7b4376662b16c8d3d7fe65430
7
- data.tar.gz: 55db020b90b57a0df643aea294aaff74cc9606cb9708da3f23b0d208e01f9f833bf10d8e7b2a265cf98bf5e51be6279742121b3e31219023f6b9afcd16502875
6
+ metadata.gz: dc5b5aefdb96b4e3d4f36591659f6eba2ec03118d1f14bc64910700dbfbbc2d7e13688edbaa297eaf6b9b7c473c67f90a2779fd8f9b87526ef62ec5feca9b590
7
+ data.tar.gz: b35dd7188dc4a20e8337adef85b37a984bc0adf9fb1f77a7acdf0e69a436dc37eea984446e1e7564fe5f9cab863a4885497c89e84021f4c15b7044ae28d12177
data/README.md CHANGED
@@ -31,7 +31,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
31
31
 
32
32
  ## Contributing
33
33
 
34
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/siyousho. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/siyousho/blob/master/CODE_OF_CONDUCT.md).
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/colorbox/siyousho. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/colorbox/siyousho/blob/master/CODE_OF_CONDUCT.md).
35
35
 
36
36
  ## License
37
37
 
@@ -39,4 +39,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
39
39
 
40
40
  ## Code of Conduct
41
41
 
42
- Everyone interacting in the Siyousho project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/siyousho/blob/master/CODE_OF_CONDUCT.md).
42
+ Everyone interacting in the Siyousho project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/colorbox/siyousho/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Siyousho
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
data/lib/siyousho.rb CHANGED
@@ -2,72 +2,95 @@
2
2
 
3
3
  require_relative 'siyousho/version'
4
4
 
5
- module Siyousho
6
- def self.save_path
7
- Rails.root.join('tmp', '仕様書')
8
- end
9
- end
5
+ require 'unparser'
6
+ require 'parser/current'
7
+ require 'method_source'
10
8
 
11
- class RSpec::Core::Example
12
- def screenshots
13
- @screenshots ||= []
14
- end
15
- end
9
+ module Siyousho
10
+ class << self
11
+ attr_accessor :current_test, :screenshots
16
12
 
17
- module Turnip
18
- module Execute
19
- alias_method :original_step, :step
13
+ def dir_path
14
+ Rails.root.join('tmp', '仕様書')
15
+ end
20
16
 
21
- def step(step_or_description, *extra_args)
22
- original_step(step_or_description, *extra_args)
17
+ def file_name
18
+ dir_path.join("#{current_test}.html")
19
+ end
23
20
 
24
- unless step_or_description.class == String
25
- dir_path = Siyousho.save_path.join(::RSpec.current_example.file_path)
26
- FileUtils.mkdir_p(dir_path)
27
- filename = "#{step_or_description.raw[:id]}.png"
28
- file_path = dir_path.join(filename)
21
+ def generate_parts(test_name, step_name)
22
+ dir_path = Siyousho.dir_path.join(test_name)
23
+ FileUtils.mkdir_p(dir_path)
24
+ filename = "#{screenshots.size}.png"
25
+ file_path = dir_path.join(filename)
29
26
 
30
- relative_file_path = ::RSpec.current_example.file_path + '/' + filename
27
+ relative_file_path = test_name + '/' + filename
31
28
 
32
- # ステップ実行後のスクリーンショット
33
- save_screenshot(file_path)
34
- screenshots << {image_path: relative_file_path, step: step_or_description.raw[:text]}
35
- else
36
- screenshots << {step: step_or_description}
37
- end
29
+ Capybara.current_session.save_screenshot(file_path)
30
+ screenshots << {image_path: relative_file_path, step: step_name}
38
31
  end
39
32
 
40
- def screenshots
41
- ::RSpec.current_example.screenshots
42
- end
33
+ def create_html
34
+ return if screenshots.empty?
35
+ html = "<html><head><title>#{current_test}</title></head><body>"
43
36
 
44
- def save_screenshot(filename)
45
- path = File.join(Siyousho.save_path, filename)
46
- Capybara.current_session.save_screenshot(path)
47
- end
37
+ screenshots.each do |screenshot|
38
+ html += "<h1>#{screenshot[:step]}</h1>"
39
+ html += "<img src='#{screenshot[:image_path]}' style='max-width: 1000px; width: auto; height: auto;'><br>" if screenshot[:image_path]
40
+ end
41
+ html += "</body></html>"
48
42
 
43
+ File.write(file_name, html)
44
+ end
49
45
  end
50
46
  end
51
47
 
52
- RSpec.configure do |config|
53
- config.after(:each) do |example|
54
- TurnipReport.generate_html
48
+ def modify_proc(proc)
49
+ buffer = Parser::Source::Buffer.new('(string)')
50
+ buffer.source = proc.source
51
+ parser = Parser::CurrentRuby.new
52
+ ast = parser.parse(buffer)
53
+
54
+ rewriter = Parser::Source::TreeRewriter.new(buffer)
55
+ ast.children.last.children.each do |child|
56
+ rewriter.insert_before(child.location.expression, "Siyousho.generate_parts(Siyousho.current_test,'#{Unparser.unparse(child)}')\n")
55
57
  end
58
+ modified_code = rewriter.process
59
+
60
+ modified_modified_code = modified_code.split("\n")[1..-2].join("\n")
61
+
62
+ Proc.new { eval(modified_modified_code) }
56
63
  end
57
64
 
58
- module TurnipReport
59
- def self.generate_html
60
- html = "<html><head><title>#{::RSpec.current_example.metadata[:example_group][:full_description]}</title></head><body>"
61
- RSpec.current_example.screenshots.each do |screenshot|
62
- html += "<h1>#{screenshot[:step]}</h1>"
63
- html += "<img src='#{screenshot[:image_path]}' style='max-width: 1000px; width: auto; height: auto;'><br>" if screenshot[:image_path]
64
- end
65
- html += "</body></html>"
65
+ module Minitest
66
+ class Test < Runnable
67
+ def run
68
+ with_info_handler do
69
+ time_it do
70
+ capture_exceptions do
71
+ Siyousho.current_test = self.name
72
+ Siyousho.screenshots = []
73
+
74
+ SETUP_METHODS.each do |hook|
75
+ self.send hook
76
+ end
66
77
 
67
- dir_path = Siyousho.save_path
68
- file_name = "#{::RSpec.current_example.metadata[:example_group][:full_description]}.html"
69
- file_path = dir_path.join(file_name)
78
+ proc = self.method(self.name).to_proc
79
+ hello_block = modify_proc(proc)
80
+ hello_block.call
81
+ end
70
82
 
71
- File.write(file_path, html)
83
+ TEARDOWN_METHODS.each do |hook|
84
+ capture_exceptions do
85
+ self.send hook
86
+ end
87
+ Siyousho.create_html
88
+ Siyousho.screenshots.clear
89
+ end
90
+ end
91
+ end
92
+
93
+ Result.from self # per contract
94
+ end
72
95
  end
73
96
  end
data/siyousho.gemspec CHANGED
@@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ['lib']
32
32
 
33
- spec.add_runtime_dependency 'turnip'
34
- spec.add_runtime_dependency 'rspec', ['>=3.0', '<4.0']
33
+ spec.add_runtime_dependency 'parser'
34
+ spec.add_runtime_dependency 'unparser'
35
+ spec.add_runtime_dependency 'method_source'
35
36
 
36
37
  # For more information and examples about making a new gem, check out our
37
38
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: siyousho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - colorbox
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-24 00:00:00.000000000 Z
11
+ date: 2023-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: turnip
14
+ name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,25 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: unparser
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '4.0'
33
+ version: '0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: '3.0'
44
- - - "<"
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: method_source
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: '4.0'
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'
47
55
  description: The Siyousho gem is designed to facilitate End-to-End (E2E) testing by
48
56
  automatically generating detailed specification documents. These documents are enriched
49
57
  with screenshots, providing a visual context for each testing step. Ideal for developers