|
18 | 18 | end |
19 | 19 |
|
20 | 20 | describe 'url' do |
21 | | - it 'URL が空の場合は無効になる' do |
22 | | - news.url = nil |
23 | | - expect(news).not_to be_valid |
24 | | - expect(news.errors[:url]).not_to be_empty |
25 | | - end |
| 21 | + context '無効な場合' do |
| 22 | + it 'URL が空の場合は無効になる' do |
| 23 | + news.url = nil |
| 24 | + expect(news).not_to be_valid |
| 25 | + expect(news.errors[:url]).not_to be_empty |
| 26 | + end |
26 | 27 |
|
27 | | - it 'URL が重複している場合は無効になる' do |
28 | | - create(:news, url: 'https://example.com/test') |
29 | | - duplicate_news = build(:news, url: 'https://example.com/test') |
30 | | - expect(duplicate_news).not_to be_valid |
31 | | - expect(duplicate_news.errors[:url]).not_to be_empty |
32 | | - end |
| 28 | + it 'URL が重複している場合は無効になる' do |
| 29 | + create(:news, url: 'https://example.com/test') |
| 30 | + duplicate_news = build(:news, url: 'https://example.com/test') |
| 31 | + expect(duplicate_news).not_to be_valid |
| 32 | + expect(duplicate_news.errors[:url]).not_to be_empty |
| 33 | + end |
33 | 34 |
|
34 | | - it 'URL形式であること' do |
35 | | - news.url = 'invalid-url' |
36 | | - expect(news).not_to be_valid |
37 | | - expect(news.errors[:url]).not_to be_empty |
| 35 | + it 'URL形式でない場合は無効になる' do |
| 36 | + news.url = 'invalid-url' |
| 37 | + expect(news).not_to be_valid |
| 38 | + expect(news.errors[:url]).not_to be_empty |
| 39 | + end |
38 | 40 | end |
39 | 41 |
|
40 | | - it 'HTTPSとHTTPを許可する' do |
41 | | - news.url = 'https://example.com' |
42 | | - expect(news).to be_valid |
| 42 | + context '有効な場合' do |
| 43 | + it 'HTTPSを許可する' do |
| 44 | + news.url = 'https://example.com' |
| 45 | + expect(news).to be_valid |
| 46 | + end |
43 | 47 |
|
44 | | - news.url = 'http://example.com' |
45 | | - expect(news).to be_valid |
| 48 | + it 'HTTPを許可する' do |
| 49 | + news.url = 'http://example.com' |
| 50 | + expect(news).to be_valid |
| 51 | + end |
46 | 52 | end |
47 | 53 | end |
48 | 54 |
|
|
0 commit comments