Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自作アプリにViewComponentを導入した
Search
siso25
November 27, 2025
Technology
68
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自作アプリにViewComponentを導入した
TokyuRuby会議16の発表資料です
siso25
November 27, 2025
Transcript
12 slides
自作アプリに ViewComponentを導入した TokyuRuby会議16 @siso255
自己紹介 @siso255 •フィヨルドブートキャンプで学習 していました •株式会社ラグザイア(2025年1月〜)
RouletteTalk トークテーマのルーレットを作成できるアプリケーション
技術スタック Framework Test / CI RSpec GitHub Actions Database PostgreSQL
infrastructure
テストについて感じていた課題 •テストケース数の割に実行に時間がかかる •ルーレットの抽選部分はStimulusメインで、システムテストでカバー •ルーレットの抽選時は3秒ほどアニメーションが入る •View Specで抽選時間をコントロールしつつテストできないか? •View SpecではJSを有効にできなさそう 1 it
'トークテーマ数を超えた回数ルーレットを実行したら選択状態をリセットする', js: true do 2 visit roulette_path(@roulette) 3 click_button 'スタート' 4 result_text = find "[data-rotate-target='resultText']", wait: 10
None
ViewComponentのPreview機能 •Preview機能を使えば、コンポーネント単位にJSありでテストが書ける •URLパラメータでルーレットの実行時間をコントロールできる
ViewComponent::Previewを使う StimulusコントローラーでValuesを追加 Stimulus 1 export default class extends Controller {
2 static values = { 3 // ルーレットが回転する時間 4 spinDuration: Number, 5 } 6 7 // スタートボタンクリック時の処理 8 start() { 9 const animation = this.rotate(this.spinDuration)
ViewComponent::Previewを使う spin_duration をコンポーネント使用時に設定できるようにする Component Slim 1 class RouletteComponent < ViewComponent::Base
2 def initialize(spin_duration:) 3 @spin_duration = spin_duration 4 end 5 end 1 .relative[ 2 data-controller="rotate" 3 data-rotate-spin-duration-value=@spin_duration
ViewComponent::Previewを使う •URLパラメータでアニメーションの時間を指定できるようにする •テストでは 0秒 に設定してwait 10 を削除 Preview RSpec 1
class RouletteComponentPreview < ViewComponent::Preview 2 def with_spin_duration(spin_duration:) 3 render Roulettes::Roulette::Component.new(spin_duration) 4 end 5 end 1 it 'トークテーマ数を超えた回数ルーレットを実行したら選択状態をリセットする', js: true do 2 visit "/rails/view_components/roulette_component/with_spin_duration?spin_duration=0" 3 click_button 'スタート' 4 result_text = find "[data-rotate-target='resultText']" # wait: 10 を削除
実行時間比較 •全件テストを10回実行した平均 •テスト件数は増えたが、wait が不要になったので実行時間は短くなった 修正前 修正後 テスト件数 44件 64件 実行時間
(秒) 36.963 22.875
まとめ •ViewComponentのPreviewを使うことで、テスト時にStimulusの動作を変え られるようになった •Stimulusメインのテスト、ルーレットのCRUDを含めた画面全体のテストをフ ァイルで分けられるようになった
More Decks by siso25
See All by siso25
1年輪読会を続けて感じたこと
siso25
0
18
Vimのイメージが変わるAstroNvim
siso25
0
85
Other Decks in Technology
See All in Technology
Welcome JXL!
dynamis
0
1.3k
データから見る AI時代のエンジニア転職と採用
junya_okura
4
1.4k
実測データからサービスの成長余力を測る。負荷シナリオ・テストデータ・限界値の設計
kazatohiei
1
190
そのイメージ、どのCIが作った? Artifact Attestationsで来歴を固定する / Which CI system created that image? Pinning provenance with Artifact Attestations
chmikata
0
450
AIが学べる子供の夏休みの自由研究教材を作ったが空振りだった話
yoshimura_datam
0
130
Webメール開発を大幅に変えたJMAPというゲームチェンジャー
tascript
9
6.2k
コーディングできない僕にBobが舞い降りた
shumpei3
0
240
IVRy における AI 時代のデータプロダクトと事業開発
ivry_presentationmaterials
0
140
フロントエンドのテストカバレッジは 100%強制がいい
bengo4com
7
4.2k
Test Impact Analysis を武器に立ち向かう、AI 時代のテスト増加に対するヌーラボのアプローチ / getting-started-datadog-test-impact-analysis
k6s4i53rx
3
910
みん強Lightning! データ基盤ひとりでできるかな
endonanana
0
230
OCI Artifact による自動運転タクシーに向けた OTA 基盤の構築
biwashi
1
310
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.7k
Well, that’s weird…
csswizardry
3
270
Crafting Experiences
bethany
1
460
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
530
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Bash Introduction
62gerente
615
220k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
Embracing the Ebb and Flow
colly
88
5.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
550
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k