Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--color
--require spec_helper
--exclude "**/black_box/*_spec.rb"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, I'll cut the full version of v1.0.0. It's at v1.0.0.rc1 (because it's been working well here so far).

gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
GIT
remote: https://github.com/nickcharlton/sack_race.git
revision: 89b4e5fff452aa6e48498aa356da87f8d1b65ae9
specs:
sack_race (1.0.0.rc1)

PATH
remote: .
specs:
Expand Down Expand Up @@ -174,6 +180,7 @@ GEM
pp (>= 0.6.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jet_black (0.7.1)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.13.2)
Expand Down Expand Up @@ -426,6 +433,7 @@ DEPENDENCIES
globalid
i18n-tasks (= 1.0.15)
image_processing
jet_black
jsbundling-rails (~> 1.3)
kaminari-i18n
launchy
Expand All @@ -434,6 +442,7 @@ DEPENDENCIES
pundit
rack-timeout
redcarpet
sack_race!
selenium-webdriver
sentry-rails
sentry-ruby
Expand Down
3 changes: 0 additions & 3 deletions bin/bundle

This file was deleted.

2 changes: 2 additions & 0 deletions gemfiles/pundit21.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails60.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails61.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails70.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails80.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ group :test do
gem "capybara"
gem "database_cleaner"
gem "formulaic"
gem "jet_black"
gem "launchy"
gem "sack_race", github: "nickcharlton/sack_race"
gem "selenium-webdriver"
gem "shoulda-matchers"
gem "timecop"
Expand Down
33 changes: 33 additions & 0 deletions spec/black_box/default_rails_app_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "rails_helper"

RSpec.describe "with a Default Rails app" do
it "works" do
create_rails_application
setup_post_model
setup_administrate

app.start_and_wait_for_ready

visit("/admin")

expect(page).to have_css("header h1#page-title", text: "Posts")
click_on "New post"

fill_in "Body", with: "Some words!"
fill_in "Title", with: "A post with words"
click_button "Create Post"

expect(page).to have_content("Post was successfully created.")
expect(page).to have_content("Show Post #1")

app.stop

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I didn't figure out yet: What if the test fails? We don't clean up the process.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickcharlton Is it possible to add a simple rescue block to catch the exception and clean up processes there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it might be. I started looking into the RSpec hooks to see what the most correct way to do this would be but I couldn't figure it out.

The trouble with a simple rescue is having to do it everywhere or have a bad time and that doesn't sit well with me.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one possible approach called around hook that will probably fit your needs in this test case.

end

def session
@session ||= JetBlack::Session.new(options: {clean_bundler_env: true})
end

def app
@app ||= TestAppProcess.new(session)
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require "jet_black/rspec"

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
Expand Down
65 changes: 65 additions & 0 deletions spec/support/acceptance_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module AcceptanceHelpers
def create_rails_application
session.create_file("Gemfile", <<~RUBY)
source "http://rubygems.org"

gem "rails"
RUBY

session.run("bundle install")

rails_new_cmd = [
"bundle exec rails new .",
"--skip-test",
"--skip-spring",
"--force"
].join(" ")

expect(session.run(rails_new_cmd))
.to be_a_success.and have_stdout("force Gemfile")
end

def gem_path
File.expand_path(Rails.root + "../../")
end

def setup_administrate
session.append_to_file("Gemfile", "gem \"administrate\", path: \"#{gem_path}\"")
session.run("bundle install")

generate_dashboards_run = session.run(
"bundle exec rails g administrate:install"
)

expect(generate_dashboards_run)
.to be_a_success.and have_stdout("create app/dashboards/post_dashboard.rb")
end

def setup_post_model
new_post_cmd = session.run([
"bundle exec rails g model post",
"title:string",
"body:text",
"published_at:datetime"
].join(" "))

expect(new_post_cmd)
.to be_a_success.and have_stdout("create app/models/post.rb")

migrate_run = session.run("bundle exec rails db:migrate")

expect(migrate_run).to be_a_success.and have_stdout("CreatePosts: migrated")
end
end

RSpec.configure do |config|
config.include Capybara::DSL, type: :black_box
config.include Capybara::RSpecMatchers, type: :black_box
config.include AcceptanceHelpers, type: :black_box

config.before(:each, type: :black_box) do
Capybara.current_driver = :chrome
Capybara.run_server = false
Capybara.app_host = "http://localhost:3000"
end
end
31 changes: 31 additions & 0 deletions spec/support/test_app_process.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class TestAppProcess
def initialize(session)
@session = session
@process =
Bundler.with_unbundled_env do
SackRace::Process.new(
"bundle exec rails server",
{
chdir: session.directory,
verbose: true
}
)
end
end

def start_and_wait_for_ready
Bundler.with_unbundled_env do
process.add_handler(:ready, "Use Ctrl-C to stop\n")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this line in the sack_race readme and couldn't understand what it did. Now I see: it waits for the string to appear in stdout, triggering the given event.

Perhaps add a line to that effect to the readme? 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! Can you think of a better name? I might've gone a bit too generic when I was thinking it through.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... Perhaps set_event_on_stdout? Looking at the code I see this is about stdout only, so I guess let's call it explicitly rather than set_event_on_output which was my first thought.

Or perhaps add_stdout_handler?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think I'm a fan of add_stdout_handler. But then I'm not sure if the wait_for_handler method also needs changing?

Or, does it suggest that there could also be a add_stderr_handler? Which is a nice idea itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think set_event_on_stdout and wait_for_event pair well.

The word "handler" would be ok, except for the pairing with "wait for handler", which is not something I would normally expect. A handler handles, and I'm not sure it's something to wait for. I think to "wait for event" is more common.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that's nice! Thanks!

process.start
process.wait_for_handler(:ready)
end
end

def stop
process.stop
end

private

attr_reader :process, :session
end
Loading