Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rust/tests/rules_tests.rs
10192 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
use tempfile::tempdir;
19
20
mod common;
21
use common::get_selenium_manager;
22
23
#[test]
24
fn rules_test_default() {
25
let tmp_dir = tempdir().expect("Unable to create temp directory");
26
let rules_file = tmp_dir.path().join("rules").join("selenium.md");
27
28
let mut cmd = get_selenium_manager();
29
cmd.current_dir(tmp_dir.path())
30
.arg("--init-rules")
31
.assert()
32
.success();
33
34
assert!(rules_file.exists());
35
36
let content = std::fs::read_to_string(rules_file).expect("Unable to read selenium.md");
37
assert!(content.contains("# Selenium Rules for AI Assistants"));
38
}
39
40
#[test]
41
fn rules_test_fallback() {
42
let tmp_dir = tempdir().expect("Unable to create temp directory");
43
let rules_dir = tmp_dir.path().join("rules");
44
std::fs::create_dir_all(&rules_dir).expect("Unable to create directory");
45
let default_rules_file = rules_dir.join("selenium.md");
46
std::fs::write(&default_rules_file, "Original").expect("Unable to write file");
47
let fallback_file = tmp_dir.path().join("selenium-rules.md");
48
49
let mut cmd = get_selenium_manager();
50
cmd.current_dir(tmp_dir.path())
51
.arg("--init-rules")
52
.assert()
53
.success();
54
55
assert!(fallback_file.exists());
56
let content = std::fs::read_to_string(fallback_file).expect("Unable to read selenium-rules.md");
57
assert!(content.contains("# Selenium Rules for AI Assistants"));
58
}
59
60
#[test]
61
fn rules_test_custom_name() {
62
let tmp_dir = tempdir().expect("Unable to create temp directory");
63
let custom_file = tmp_dir.path().join("my-rules.md");
64
65
let mut cmd = get_selenium_manager();
66
cmd.current_dir(tmp_dir.path())
67
.arg("--init-rules")
68
.arg("my-rules.md")
69
.assert()
70
.success();
71
72
assert!(custom_file.exists());
73
let content = std::fs::read_to_string(custom_file).expect("Unable to read file");
74
assert!(content.contains("# Selenium Rules for AI Assistants"));
75
}
76
77
#[test]
78
fn rules_no_overwrite_test() {
79
let tmp_dir = tempdir().expect("Unable to create temp directory");
80
let rules_dir = tmp_dir.path().join("rules");
81
std::fs::create_dir_all(&rules_dir).expect("Unable to create directory");
82
let rules_file = rules_dir.join("selenium.md");
83
std::fs::write(&rules_file, "Original content").expect("Unable to write file");
84
85
let mut cmd = get_selenium_manager();
86
cmd.current_dir(tmp_dir.path())
87
.arg("--init-rules")
88
.assert()
89
.success();
90
91
// It should NOT overwrite rules/selenium.md, but instead fallback to selenium-rules.md
92
let content = std::fs::read_to_string(&rules_file).expect("Unable to read selenium.md");
93
assert_eq!(content, "Original content");
94
95
let fallback_file = tmp_dir.path().join("selenium-rules.md");
96
assert!(fallback_file.exists());
97
}
98
99
#[test]
100
fn rules_custom_no_overwrite_test() {
101
let tmp_dir = tempdir().expect("Unable to create temp directory");
102
let custom_file = tmp_dir.path().join("my-rules.md");
103
std::fs::write(&custom_file, "Original content").expect("Unable to write file");
104
105
let mut cmd = get_selenium_manager();
106
cmd.current_dir(tmp_dir.path())
107
.arg("--init-rules")
108
.arg("my-rules.md")
109
.assert()
110
.failure();
111
112
let content = std::fs::read_to_string(custom_file).expect("Unable to read file");
113
assert_eq!(content, "Original content");
114
}
115
116