Skip to content

Commit

Permalink
🐛 Add unique timestamp to page names in tests
Browse files Browse the repository at this point in the history
Ensured page names do not conflict by appending current timestamp.
  • Loading branch information
r74tech committed Oct 8, 2024
1 parent 3b15e86 commit 2aa26be
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
73 changes: 34 additions & 39 deletions wikidotrb/spec/module/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
let(:client) { Wikidotrb::Module::Client.new(username: username, password: password) }
let(:site) { client.site.get(site_domain) }

before(:all) do
# Assign the test_page_name once before all examples run
@test_page_name = "test-page-#{Time.now.to_i}"
before(:each) do |example|
# テスト名の末尾を元にページ名を動的に生成
suffix = example.description.split.last.downcase
@test_page_name = "test-page-#{suffix}-#{Time.now.to_i}"
end

describe "Page management" do
Expand Down Expand Up @@ -49,41 +50,39 @@
client.finalize if client.is_logged_in
end

context "Creating a page" do
it "新しいページを作成できること" do
# ページ作成時にロックがかかっている場合の対応
page = nil
begin
page = site.page.create(
context "Creating a page" do
it "新しいページを作成できる_create" do
page = nil
begin
page = site.page.create(
fullname: @test_page_name,
title: test_page_title,
source: test_page_source,
force_edit: true
)
rescue Wikidotrb::Common::Exceptions::TargetErrorException => e
if e.message.include?("locked")
sleep(1)
retry
else
raise e
end
end
expect(page.fullname).to eq(@test_page_name)
expect(page.title).to eq(test_page_title)
expect(page.source.wiki_text).to eq(test_page_source)
end
end

context "Editing a page" do
it "既存のページを編集できる_edit" do
page = site.page.get(@test_page_name, raise_when_not_found: false)
page ||= site.page.create(
fullname: @test_page_name,
title: test_page_title,
source: test_page_source,
force_edit: true
)
rescue Wikidotrb::Common::Exceptions::TargetErrorException => e
if e.message.include?("locked")
sleep(1)
retry
else
raise e
end
end
expect(page.fullname).to eq(@test_page_name)
expect(page.title).to eq(test_page_title)
expect(page.source.wiki_text).to eq(test_page_source)
end
end

context "Editing a page" do
it "既存のページを編集できること" do
# 既存のページがある場合はスキップ、または再試行
page = site.page.get(@test_page_name, raise_when_not_found: false)
page ||= site.page.create(
fullname: @test_page_name,
title: test_page_title,
source: test_page_source,
force_edit: true
)

# ページを編集
new_source = "This is the updated content of the page."
Expand All @@ -97,8 +96,7 @@


context "Searching for pages" do
it "指定したクエリに基づいてページを検索できること" do
# ページ作成
it "指定したクエリに基づいてページを検索できる_search" do
site.page.create(
fullname: @test_page_name,
title: test_page_title,
Expand All @@ -116,8 +114,7 @@
end

context "Deleting a page" do
it "既存のページを削除できること" do
# ページ作成
it "既存のページを削除できる_delete" do
site.page.create(
fullname: @test_page_name,
title: test_page_title,
Expand All @@ -128,10 +125,8 @@
page = site.page.get(@test_page_name)
expect(page).not_to be_nil

# ページを削除
page.destroy

# 削除後の存在確認
expect do
site.page.get(@test_page_name)
end.to raise_error(Wikidotrb::Common::Exceptions::NotFoundException)
Expand Down
5 changes: 2 additions & 3 deletions wikidotrb/spec/module/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
let(:client) { Wikidotrb::Module::Client.new(username: username, password: password) }
let(:site) { Wikidotrb::Module::Site.from_unix_name(client: client, unix_name: site_domain) }

# 新しいページに関する情報を定義
let(:new_page_fullname) { "new-page" }
let(:new_page_fullname) { "new-page-#{Time.now.to_i}" }
let(:page_title) { "Test Page Title" }
let(:page_source) { "This is a test page." }

Expand Down Expand Up @@ -50,7 +49,7 @@
end

before(:each) do
# Ensure the `new-page` does not exist before each test
# Ensure the `new_page_fullname` does not exist before each test
site.page.get(new_page_fullname, raise_when_not_found: false)&.destroy
end

Expand Down

0 comments on commit 2aa26be

Please sign in to comment.