Skip to content

Commit

Permalink
Merge pull request #5 from stepful/wa/rspec
Browse files Browse the repository at this point in the history
rspec support
  • Loading branch information
wyattades authored May 15, 2024
2 parents 4741798 + ac5ee7d commit 4f3f233
Show file tree
Hide file tree
Showing 72 changed files with 4,954 additions and 4,457 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Style/MethodCallWithArgsParentheses:
- yield
- require
- require_relative
Exclude:
- 'spec/**/*'
- 'test/**/*'
Style/AccessModifierDeclarations:
Enabled: true
EnforcedStyle: inline
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
source "https://rubygems.org"

gem "minitest", "~> 5.22"
gem "standard"
gem "rubocop"
gem "prettier_print", "~> 1.2"
gem "syntax_tree", "~> 6.1"
gem "syntax_tree-haml", "~> 4.0"
gem "syntax_tree-rbs", "~> 1.0"

gem "cyperful", path: "."
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
PATH
remote: .
specs:
cyperful (0.1.10)
capybara (~> 3)
listen (~> 3)
parser (~> 3)
webrick-websocket (~> 0.0.3)

GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.2)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
ffi (1.16.3)
haml (6.3.0)
temple (>= 0.8.2)
thor
tilt
json (2.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
matrix (0.4.2)
mini_mime (1.1.5)
minitest (5.22.3)
nokogiri (1.16.4-arm64-darwin)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
public_suffix (5.0.4)
racc (1.7.3)
rack (2.2.9)
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (3.4.4)
abbrev
regexp_parser (2.9.0)
Expand Down Expand Up @@ -64,12 +100,19 @@ GEM
thor (1.3.1)
tilt (2.3.0)
unicode-display_width (2.5.0)
webrick (1.8.1)
webrick-websocket (0.0.3)
webrick (~> 1.3)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
arm64-darwin-22
arm64-darwin-23

DEPENDENCIES
cyperful!
minitest (~> 5.22)
prettier_print (~> 1.2)
rubocop
standard
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ https://github.com/stepful/cyperful/assets/992076/dd1ef39c-98ca-48f3-8c3d-99ae05

## Framework support

🚨 Cyperful is in **BETA** and you will likely encounter issues/bugs! I have only confirmed it works on the default Rails 7.0 testing stack: `Minitest` and `Capybara`.
🚨 Cyperful is in **BETA** and you will likely encounter issues/bugs! We currently only support: Rails 7.1, Ruby 3.2.1, `Minitest`/`RSpec`, `capybara`, and `selenium` with Chrome.

Please open a Github issue if you'd like to see support for other test frameworks (such as RSpec) or any other specific setups.
Try it out, then please open a Github issue if you'd like to see support for any other specific frameworks/setups.

## Installation

Expand All @@ -34,15 +34,42 @@ group :test do
end
```

Follow the instructions for your test framework:

### RSpec

In your `rails_helper.rb` file, add the following:

```ruby
CYPERFUL = !!ENV["CYPERFUL"]

require "cyperful/rspec" if CYPERFUL

RSpec.configure do |config|
# make sure we setup the browser-driver BEFORE Cyperful's setup
config.prepend_before(:example, type: :system) do
# Cyperful only supports Selenium + Chrome
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end

# ...
end
```

### Minitest

In your `application_system_test_case.rb` file, add the following:

```ruby
CYPERFUL = !!ENV["CYPERFUL"]

require "cyperful" if CYPERFUL
require "cyperful/minitest" if CYPERFUL

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include Cyperful::SystemTestHelper if CYPERFUL
include Cyperful::Minitest::SystemTestHelper if CYPERFUL

# Cyperful only supports Selenium + Chrome
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]

# ...
end
Expand Down
1 change: 1 addition & 0 deletions cyperful.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Gem::Specification.new do |s|
s.files = Dir["lib/**/*.rb", "public/**/*"]

s.add_dependency("capybara", "~> 3")
s.add_dependency("parser", "~> 3")
s.add_dependency("listen", "~> 3")
s.add_dependency("webrick-websocket", "~> 0.0.3")
end
29 changes: 28 additions & 1 deletion lib/cyperful.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,36 @@ def self.config
@config ||= Config.new
end

def self.logger
@logger ||= Cyperful::Logger.new
end

def self.test_framework
@test_framework || raise("Cyperful not set up yet")
end
def self.rspec?
@test_framework == :rspec
end
def self.minitest?
@test_framework == :minitest
end

def self.current
@current
end
def self.setup(test_class, test_name)
puts "Setting up Cyperful for: #{test_class}##{test_name}"
@test_framework =
if defined?(RSpec::Core::ExampleGroup) &&
test_class < RSpec::Core::ExampleGroup
:rspec
elsif defined?(ActiveSupport::TestCase) &&
test_class < ActiveSupport::TestCase
:minitest
else
raise "Unsupported test framework for class: #{test_class.name}"
end

logger.puts "init test: \"#{rspec? ? test_name : "#{test_class}##{test_name}"}\""

# must set `Cyperful.current` before calling `async_setup`
@current ||= Cyperful::Driver.new
Expand All @@ -62,8 +87,10 @@ def self.add_step_at_methods(*mods_or_methods)
end

require "cyperful/commands"
require "cyperful/logger"
require "cyperful/test_parser"
require "cyperful/ui_server"
require "cyperful/driver"
require "cyperful/framework_helper"
require "cyperful/framework_injections"
require "cyperful/railtie" if defined?(Rails::Railtie)
Loading

0 comments on commit 4f3f233

Please sign in to comment.