Skip to content

Commit d30296f

Browse files
committed
Add test for Cli
1 parent 06f1c05 commit d30296f

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem "rake"
66
gem "rspec"
77
gem "rspec-its"
88
gem "rspec-parameterized"
9+
gem "rspec-temp_dir"
910
gem "rubocop", require: false
1011
gem "rubocop_auto_corrector", require: false
1112
gem "serverspec"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ GEM
8888
binding_of_caller
8989
rspec-parameterized-core (< 2)
9090
rspec-support (3.13.1)
91+
rspec-temp_dir (1.1.1)
92+
rspec (>= 3.0)
9193
rubocop (1.66.1)
9294
json (~> 2.3)
9395
language_server-protocol (>= 3.17.0)
@@ -154,6 +156,7 @@ DEPENDENCIES
154156
rspec
155157
rspec-its
156158
rspec-parameterized
159+
rspec-temp_dir
157160
rubocop
158161
rubocop_auto_corrector
159162
serverspec

_tools/ruby_h_to_go/lib/ruby_h_to_go/cli.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ def perform
3030
go_fmt
3131
end
3232

33-
private
34-
35-
# @return [RubyHeaderParser::Parser]
36-
def parser
37-
@parser ||= RubyHeaderParser::Parser.new(header_dir)
38-
end
39-
4033
def write_type_definitions_to_go_file
4134
type_definitions = parser.extract_type_definitions.map do |definition|
4235
RubyHToGo::TypeDefinition.new(definition:, header_dir:)
@@ -67,6 +60,13 @@ def write_function_definitions_to_go_file
6760
end
6861
end
6962

63+
private
64+
65+
# @return [RubyHeaderParser::Parser]
66+
def parser
67+
@parser ||= RubyHeaderParser::Parser.new(header_dir)
68+
end
69+
7070
# Clean all generated files in dist/
7171
def clean_generated_files
7272
FileUtils.rm_f(Dir.glob(File.join(dist_dir, "*.go")))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RubyHToGo::Cli do
4+
include_context "uses temp dir"
5+
6+
let(:cli) do
7+
RubyHToGo::Cli.new(
8+
header_dir: RbConfig::CONFIG["rubyhdrdir"],
9+
dist_dir: temp_dir,
10+
)
11+
end
12+
13+
describe "#write_type_definitions_to_go_file" do
14+
subject { cli.write_type_definitions_to_go_file }
15+
16+
it { expect { subject }.not_to raise_error }
17+
end
18+
19+
describe "#write_struct_definitions_to_go_file" do
20+
subject { cli.write_struct_definitions_to_go_file }
21+
22+
it { expect { subject }.not_to raise_error }
23+
end
24+
25+
describe "#write_function_definitions_to_go_file" do
26+
subject { cli.write_function_definitions_to_go_file }
27+
28+
it { expect { subject }.not_to raise_error }
29+
end
30+
end

_tools/ruby_h_to_go/spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "rspec/its"
44
require "rspec/parameterized"
5+
require "rspec/temp_dir"
56

67
require_relative "../lib/ruby_header_parser"
78
require_relative "../lib/ruby_h_to_go"

0 commit comments

Comments
 (0)