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
62
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自作アプリにViewComponentを導入した
TokyuRuby会議16の発表資料です
siso25
November 27, 2025
More Decks by siso25
See All by siso25
1年輪読会を続けて感じたこと
siso25
0
16
Vimのイメージが変わるAstroNvim
siso25
0
82
Other Decks in Technology
See All in Technology
Metadata - Section 1: HTML Basics
mohab1
0
120
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
340
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
120
夫婦で子育てするための育児標準化
codmoninc
PRO
0
460
会社説明資料
persolserverworks
0
9.8k
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
650
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
930
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
890
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
160
FinOps Agentが生んだ技術負債:コスト自動調査の落とし穴と解消までの道のり
oasis1994liveforever
2
140
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Balancing Empowerment & Direction
lara
6
1.3k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
The SEO Collaboration Effect
kristinabergwall1
1
590
Optimizing for Happiness
mojombo
378
71k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The browser strikes back
jonoalderson
0
1.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Transcript
自作アプリに 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を含めた画面全体のテストをフ ァイルで分けられるようになった